code:
:: weaponsManufacturing [nobr jump-to-safe jump-from-safe]

<<set $nextButton = "Back", $nextLink = "Main", _baseUpgradeTime = App.SecExp.weapManuUpgrade.baseTime()>>

This sector of the arcology has been dedicated to weapons manufacturing. These factories supply
<<if $militiaUnits.length > 0>> your militia and<</if>>
<<if $slaveUnits.length > 0>> your slave soldiers and<</if>>
<<if $mercenaries > 0>> your mercenaries and<</if>>
many small old world nations as the advanced technology that Free Cities have available is hard to come by otherwise.
<<if $SecExp.buildings.weapManu.productivity == 1>>

Production is completely manned by human workers. The complex has close to zero automation.
<<elseif $SecExp.buildings.weapManu.productivity == 2>>

Production is mostly handled by human workers. A few of the most tiresome tasks are handled by robots.
<<elseif $SecExp.buildings.weapManu.productivity == 3>>

A good part of production is handled by robots with humans handling the most complex tasks.
<<elseif $SecExp.buildings.weapManu.productivity == 4>>

Almost all production is handled by robots, with humans acting as support for the machines.
<<else>>

All production here is handled by robots. The few humans working in the complex occupy themselves exclusively with management and quality assurance.
<</if>>
<<if $SecExp.buildings.weapManu.lab == 1>>

There's a very spartan lab attached to the complex that occupies itself mainly with weapons testing and small adjustments to the manufacturing process.
<<elseif $SecExp.buildings.weapManu.lab == 2>>

There's a lab attached to the complex. It mainly test weapons effectiveness and manufacturing efficiency, but has enough equipment and personnel to develop new technology.
<<else>>

There's a large lab attached to the complex. The complement of equipment and personnel makes it a great beacon of military science in an otherwise ignorant world.
<</if>>

<<if $SecExp.buildings.weapManu.menials > 0>>

Assigned here are $SecExp.buildings.weapManu.menials slaves working to produce as much equipment as possible.
<<else>>

There are no assigned menial slaves here. The spaces is manned exclusively by low rank citizens.
<</if>>
You own <<print num($menials)>> free menial slaves. This manufacturing complex can house 500 at most, with <<print 500 - $SecExp.buildings.weapManu.menials>> free slots.

<<set _popCap = menialPopCap()>>
<<set _menialPrice = menialSlaveCost()>>
<<set _bulkMax = _popCap.value-$menials-$fuckdolls-$menialBioreactors>>
<<if $cash > _menialPrice>>
	<<if _bulkMax > 0 || $menials+$fuckdolls+$menialBioreactors == 0>>
		[[Buy|weaponsManufacturing][$menials+=1,$menialSupplyFactor-=1,cashX(forceNeg(_menialPrice), "menialTransfer")]]
		<<if $cash > (menialSlaveCost(10))*10>>
			[[(x10)|weaponsManufacturing][$menials+=10,$menialSupplyFactor-=10,cashX(forceNeg((menialSlaveCost(10))*10), "menialTransfer")]]
		<</if>>
		<<if $cash > (menialSlaveCost(100))*100>>
			[[(x100)|weaponsManufacturing][$menials+=100,$menialSupplyFactor-=100,cashX(forceNeg((menialSlaveCost(100))*100), "menialTransfer")]]
		<</if>>
		<<if $cash > (_menialPrice+1)*2>>
			<<set _menialBulkPremium = Math.trunc(1 + Math.clamp($cash/_menialPrice,0,_bulkMax)/400)>>
			[[(max)|weaponsManufacturing][$menials+=Math.trunc(Math.clamp($cash/(_menialPrice+_menialBulkPremium),0,_bulkMax)),$menialSupplyFactor-=Math.trunc(Math.clamp($cash/(_menialPrice+_menialBulkPremium),0,_bulkMax)),cashX(forceNeg(Math.trunc(Math.clamp($cash/(_menialPrice+_menialBulkPremium),0,_bulkMax)*(_menialPrice+_menialBulkPremium))), "menialTransfer")]]
		<</if>>
		//Bulk transactions may require offering a premium.//
	<</if>>
<</if>>

<<if $SecExp.buildings.weapManu.menials < 500>>
	<<if $menials >= 1>>
		<<link "Transfer a menial slave" "weaponsManufacturing">>
			<<set $menials--, $SecExp.buildings.weapManu.menials++>>
		<</link>>
	<</if>>
	<<if $menials >= 10 && $SecExp.buildings.weapManu.menials <= 490>>
		|
		<<link "Transfer 10 menial slaves" "weaponsManufacturing">>
			<<set $menials -= 10, $SecExp.buildings.weapManu.menials += 10>>
		<</link>>
	<</if>>
	<<if $menials >= 100 && $SecExp.buildings.weapManu.menials <= 400>>
		|
		<<link "Transfer 100 menial slaves" "weaponsManufacturing">>
			<<set $menials -= 100, $SecExp.buildings.weapManu.menials += 100>>
		<</link>>
	<</if>>
	<<if $menials > 0>>
		|
		<<link "Transfer all free menial slaves" "weaponsManufacturing">>
			<<if $menials > 500 - $SecExp.buildings.weapManu.menials>>
				<<set $menials -= 500 - $SecExp.buildings.weapManu.menials>>
				<<set $SecExp.buildings.weapManu.menials = 500>>
			<<else>>
				<<set $SecExp.buildings.weapManu.menials += $menials, $menials = 0>>
			<</if>>
		<</link>>
	<</if>>
<<else>>
	The complex does not require more workers.
<</if>>
<<if $SecExp.buildings.weapManu.menials > 0>>

 <<link "Transfer out all menial slaves" "weaponsManufacturing">>
		<<set $menials += $SecExp.buildings.weapManu.menials, $SecExp.buildings.weapManu.menials = 0>>
	<</link>>
<</if>>

<<if $SecExp.buildings.weapManu.productivity < 5>>

 <<link "Invest in automating the complex" "weaponsManufacturing">>
		<<run cashX(forceNeg(10000 * $SecExp.buildings.weapManu.productivity), "capEx")>>
		<<set $SecExp.buildings.weapManu.productivity++>>
		<<for _i = 0; _i < $SecExp.buildings.weapManu.upgrades.queue.length; _i++>>
			<<if $SecExp.buildings.weapManu.upgrades.queue[_i].time > 0>>
				<<set _percentComplete = $SecExp.buildings.weapManu.upgrades.queue[_i].time / (_baseUpgradeTime / ($SecExp.buildings.weapManu.productivity - 1))>>
				<<set _newTime = Math.ceil(_percentComplete * _baseUpgradeTime / $SecExp.buildings.weapManu.productivity)>>
				<<set $SecExp.buildings.weapManu.upgrades.queue[_i].time = _newTime>>
			<</if>>
		<</for>>
	<</link>>
	//Will cost <<print cashFormat(10000 * $SecExp.buildings.weapManu.productivity)>> and will increase the facility income in addition to speeding up upgrade production.//
<<elseif $SecExp.buildings.weapManu.lab < 3>>

You have fully automated the complex.
<</if>>
<<if $SecExp.buildings.weapManu.lab < 3>>

 <<link "Invest in research and development" "weaponsManufacturing">>
		<<run cashX(forceNeg(10000 * $SecExp.buildings.weapManu.lab), "capEx")>>
		<<set $SecExp.buildings.weapManu.lab++>>
	<</link>>
	//Will cost <<print cashFormat(10000 * $SecExp.buildings.weapManu.lab)>> and will increase the facility income as well as unlock upgrades for our troops//
<<elseif $SecExp.buildings.weapManu.productivity < 5>>

You have fully upgraded and funded the R&D department
<</if>>
<<if $SecExp.buildings.weapManu.lab >= 3 && $SecExp.buildings.weapManu.productivity >= 5>>
	The facility is completely automated and its R&D department is fully upgraded and funded.
<</if>>

__Markets__: //You are free to sell to whoever you please, but expect hostile forces of a certain kind to be stronger if we'll ever meet in battle.//
<<if $SecExp.buildings.weapManu.sellTo.citizen == 1>>

We are currently selling our weapons to the domestic market of the arcology.
	[[Forbid|weaponsManufacturing][$SecExp.buildings.weapManu.sellTo.citizen = 0]]
<<else>>

We are not selling our weaponry to our citizens.
	[[Allow|weaponsManufacturing][$SecExp.buildings.weapManu.sellTo.citizen = 1]]
<</if>>
<<if $SecExp.buildings.weapManu.sellTo.raiders == 1>>

We are currently selling our weapons to various groups of outlaws, also known as raiders.
	[[Forbid|weaponsManufacturing][$SecExp.buildings.weapManu.sellTo.raiders = 0]]
<<else>>

We are not selling our weaponry to raiders.
	[[Allow|weaponsManufacturing][$SecExp.buildings.weapManu.sellTo.raiders = 1]]
<</if>>
<<if $SecExp.buildings.weapManu.sellTo.oldWorld == 1>>

We are currently selling our weapons to many old world nations.
	[[Forbid|weaponsManufacturing][$SecExp.buildings.weapManu.sellTo.oldWorld = 0]]
<<else>>

We are not selling our weaponry to old world nations.
	[[Allow|weaponsManufacturing][$SecExp.buildings.weapManu.sellTo.oldWorld = 1]]
<</if>>
<<if $SecExp.buildings.weapManu.sellTo.FC == 1>>

We are currently selling our weapons to other Free Cities.
	[[Forbid|weaponsManufacturing][$SecExp.buildings.weapManu.sellTo.FC = 0]]
<<else>>

We are not selling our weaponry to other Free Cities.
	[[Allow|weaponsManufacturing][$SecExp.buildings.weapManu.sellTo.FC = 1]]
<</if>>

<<set _time = Math.ceil(_baseUpgradeTime / $SecExp.buildings.weapManu.productivity)>>

Upgrades: With our current industrial and research capabilities upgrades will be finished in _time weeks.
<<if App.SecExp.weapManuUpgrade.fully().bots && App.SecExp.weapManuUpgrade.fully().human>>
	<<run delete $SecExp.buildings.weapManu.upgrades.queue>>
<<else>>
	<<set $SecExp.buildings.weapManu.upgrades.queue = $SecExp.buildings.weapManu.upgrades.queue || []>>

	<<if $SecExp.buildings.weapManu.lab < 3>>

Upgrade the research facility further to unlock additional upgrades.
	<</if>>

Security Drones:
	<<if App.SecExp.weapManuUpgrade.fully().bots>>
		You have fully upgraded the security drones.
	<<else>>

 <<includeDOM App.SecExp.weapManuUpgrade.purchase(-1)>>

		<<if $SecExp.buildings.weapManu.lab >= 2>>

 <<includeDOM App.SecExp.weapManuUpgrade.purchase(-2)>>

		<</if>>
		<<if $SecExp.buildings.weapManu.lab >= 3>>

 <<includeDOM App.SecExp.weapManuUpgrade.purchase(-3)>>

		<</if>>

	<</if>>

Troops:
	<<if $SF.Toggle && $SF.Active >= 1 && (App.SecExp.getAppliedUpgrades('human').attack >= 4 || App.SecExp.getAppliedUpgrades('human').hp >= 4 || App.SecExp.getAppliedUpgrades('human').morale >= 40 || App.SecExp.getAppliedUpgrades('human').defense >= 4)>>
		You have fully upgraded your human troops.
	<<elseif App.SecExp.getAppliedUpgrades('human').attack >= 2 || App.SecExp.getAppliedUpgrades('human').hp >= 2 || App.SecExp.getAppliedUpgrades('human').morale >= 20 || App.SecExp.getAppliedUpgrades('human').defense >= 2>>
		<<if $SF.Toggle && $SF.Active >= 1>>
			<<set _reasons = []>>
			<<if $SF.Squad.Drugs < 8>>
				<<set _reasons.push('drug lab needs more advanced equipement')>>
			<</if>>
			<<if $SecExp.edicts.SFSupportLevel < 2 || $SecExp.edicts.SFSupportLevel < 4 || $SecExp.edicts.SFSupportLevel < 5>>
				<<set _reasons.push('support contract needs more clauses')>>
			<</if>>
			<<if $SF.Squad.Firebase < 7>>
				<<set _reasons.push('Firebase would likely require additional expansion(s)')>>
			<</if>>
			<<set _reasons.join(',')>>
			With support from $SF.Lower, we may be able to further upgrade our troops.
			<<if _reasons.length > 0>>
The Colonel says that the; _reasons.<</if>>
		<<else>>
			You have fully upgraded your human troops.
		<</if>>
	<</if>>

 <<includeDOM App.SecExp.weapManuUpgrade.purchase(0)>>

 <<includeDOM App.SecExp.weapManuUpgrade.purchase(1)>>

	<<if $SecExp.buildings.weapManu.lab >= 2>>

 <<includeDOM App.SecExp.weapManuUpgrade.purchase(2)>>

 <<includeDOM App.SecExp.weapManuUpgrade.purchase(3)>>

	<</if>>
	<<if $SecExp.buildings.weapManu.lab >= 3>>

 <<includeDOM App.SecExp.weapManuUpgrade.purchase(4)>>

 <<includeDOM App.SecExp.weapManuUpgrade.purchase(5)>>

	<</if>>
	<<if $SF.Toggle && $SF.Active >= 1>>
		<<if $SecExp.buildings.weapManu.lab >= 2 && $SecExp.edicts.SFSupportLevel >= 2 && $SF.Squad.Firebase >= 7>>

 <<includeDOM App.SecExp.weapManuUpgrade.purchase(6)>>

		<</if>>
		<<if $SecExp.buildings.weapManu.lab >= 2 && $SecExp.edicts.SFSupportLevel >= 4 && $SF.Squad.Drugs >= 8>>

 <<includeDOM App.SecExp.weapManuUpgrade.purchase(7)>>

		<</if>>
		<<if $SecExp.buildings.weapManu.lab >= 3 && $SecExp.edicts.SFSupportLevel >= 5>>

 <<includeDOM App.SecExp.weapManuUpgrade.purchase(8)>>

		<</if>>
	<</if>>

	<<for _i = 0; _i < $SecExp.buildings.weapManu.upgrades.queue.length; _i++>>
		<<set _current = App.SecExp.weapManuUpgrade.current($SecExp.buildings.weapManu.upgrades.queue[_i].ID)>>
		<<if _i === 0>>
Currently developing<<else>>
<<= ordinalSuffix(_i + 1)>> in queue<</if>>:
		_current.dec for _current.unit. It will enhance their _current.purpose.
		Estimated completion time is <<= numberWithPluralOne($SecExp.buildings.weapManu.upgrades.queue[_i].time, "week")>>
	<</for>>
<</if>>

<<set _completed = $SecExp.buildings.weapManu.upgrades.completed>>
<<if _completed.length > 0>>

	You have completed the following projects:
	<<for _i = 0; _i < _completed.length; _i++>>
		<<= App.SecExp.weapManuUpgrade.current($SecExp.buildings.weapManu.upgrades.completed[_i]).dec>><<if _i < _completed.length - 1>>,<<else>>.<</if>>
	<</for>>

<</if>>
<<set _cost = Math.trunc(10000*$upgradeMultiplierArcology)>>

[[Return this sector to standard manufacturing|Main][delete $SecExp.buildings.weapManu, cashX(-_cost, "capEx"), App.Arcology.cellUpgrade($building, App.Arcology.Cell.Manufacturing, "Weapon Manufacturing", "Manufacturing")]] //Costs <<print cashFormat(_cost)>>//


code:
:: edicts [nobr jump-to-safe jump-from-safe]

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

//Passing any edict will cost <<print cashFormat(5000)>> and some authority. More edicts will become available as the arcology develops.//
<<run App.UI.tabBar.handlePreSelectedTab($tabChoice.edicts)>>

<button class="tab-links" onclick="App.UI.tabBar.openTab(event, 'Society')" id="tab Society">Society</button>
<<if $SecExp.battles.victories + $SecExp.battles.losses > 0 || $SecExp.rebellions.victories + $SecExp.rebellions.losses > 0 || $mercenaries > 0>>
	<button class="tab-links" onclick="App.UI.tabBar.openTab(event, 'Military')" id="tab Military">Military</button>
<</if>>

	<<if $SecExp.edicts.alternativeRents == 1>>

''Alternative rent payment:'' you are allowing citizens to pay for their rents in menial slaves rather than cash.
		[[Repeal|edicts][$SecExp.edicts.alternativeRents = 0]]
	<<else>>

''Alternative rent payment:'' allow citizens to pay for their rents in menial slaves rather than cash, if so they wish.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.alternativeRents = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will decrease rents, but will supply a small amount of menial slaves each week.//
	<</if>>

	<<if $SecExp.edicts.enslavementRights == 1>>

''Enslavement rights:'' you are the only authority able to declare a person enslaved or not.
		[[Repeal|edicts][$SecExp.edicts.enslavementRights = 0]]
	<<else>>

''Enslavement rights:'' the arcology owner will be the only authority able to declare a person enslaved or not.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.enslavementRights = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will provide cash each week. The higher the flux of citizens to slaves the higher the income. Will cost a small amount of authority each week.//
	<</if>>

	<<if $SecExp.buildings.secHub>>
		<<set _secUpgrades = $SecExp.buildings.secHub.upgrades>>
		<<if $SecExp.edicts.sellData === 1>>

''Private Data marketization:'' you are selling private citizens' data to the best bidder.
			[[Repeal|edicts][$SecExp.edicts.sellData = 0]]
		<<elseif $SecExp.edicts.sellData === 0 && Object.values(_secUpgrades.security).reduce((a, b) => a + b) > 0 || Object.values(_secUpgrades.crime).reduce((a, b) => a + b) > 0 || Object.values(_secUpgrades.intel).reduce((a, b) => a + b) > 0>>

''Private Data marketization:'' allow the selling of private citizens' data.
			<<if $SecExp.core.authority >= 1000>>
				[[Implement|edicts][$SecExp.edicts.sellData = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
			<<else>>

//Not enough Authority.//
			<</if>>

    //Will generate income dependent on the amount of upgrades installed in the security HQ, but will cost a small amount of authority each week.//
		<</if>>
	<</if>>
	<<if $SecExp.buildings.propHub>>
		<<if $SecExp.edicts.propCampaignBoost == 1>>

''Obligatory educational material:'' you are forcing residents to read curated educational material about the arcology.
			[[Repeal|edicts][$SecExp.edicts.propCampaignBoost = 0]]
		<<else>>

''Obligatory educational material:'' force residents to read curated educational material about the arcology.
			<<if $SecExp.core.authority >= 1000>>
				[[Implement|edicts][$SecExp.edicts.propCampaignBoost = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
			<<else>>

//Not enough Authority.//
			<</if>>

    //Will increase the effectiveness of propaganda campaigns, but will incur upkeep costs.//
		<</if>>
	<</if>>
	<<if $SecExp.buildings.transportHub>>
		<<if $SecExp.edicts.tradeLegalAid == 1>>

''Legal aid for new businesses:'' New businesses can rely on your help for legal expenses and issues.
			[[Repeal|edicts][$SecExp.edicts.tradeLegalAid = 0]]
		<<else>>

''Legal aid for new businesses:'' Support new businesses in the arcology by helping them cover legal costs and issues.
			<<if $SecExp.core.authority >= 1000>>
				[[Implement|edicts][$SecExp.edicts.tradeLegalAid = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
			<<else>>

//Not enough Authority.//
			<</if>>

    //Will increase trade, but will incur upkeep costs.//
		<</if>>
		<<if $SecExp.edicts.taxTrade == 1>>

''Trade tariffs:'' all goods transitioning in your arcology have to pay a transition fee.
			[[Repeal|edicts][$SecExp.edicts.taxTrade = 0]]
		<<else>>

''Trade tariffs:'' all goods transitioning in your arcology will have to pay a transition fee.
			<<if $SecExp.core.authority >= 1000>>
				[[Implement|edicts][$SecExp.edicts.taxTrade = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
			<<else>>

//Not enough Authority.//
			<</if>>

    //Will provide income based on trade level, but will negatively affect trade.//
		<</if>>
	<</if>>

	<<if $arcologies[0].FSPaternalist != "unset">>
		<<if $SecExp.edicts.slaveWatch == 1>>

''@@.lime;Slave mistreatment watch:@@'' slaves are able access a special security service in case of mistreatment.
			[[Repeal|edicts][$SecExp.edicts.slaveWatch = 0]]
		<<else>>

''@@.lime;Slave mistreatment watch:@@'' slaves will be able access a special security service in case of mistreatment.
			<<if $SecExp.core.authority >= 1000>>
				[[Implement|edicts][$SecExp.edicts.slaveWatch = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
			<<else>>

//Not enough Authority.//
			<</if>>

    //Will help advance paternalism, but will incur upkeep costs.//
		<</if>>
	<</if>>

	<<if $arcologies[0].FSChattelReligionist >= 40>>
		<<if $SecExp.edicts.subsidyChurch == 1>>

''@@.lime;Religious activities subsidy:@@'' you are providing economic support to religious activities following the official dogma.
			[[Repeal|edicts][$SecExp.edicts.subsidyChurch = 0]]
		<<else>>

''@@.lime;Religious activities subsidy:@@'' will provide economic support to religious activities following the official dogma.
			<<if $SecExp.core.authority >= 1000>>
				[[Implement|edicts][$SecExp.edicts.subsidyChurch = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
			<<else>>

//Not enough Authority.//
			<</if>>

    //Will provide authority each week, but will incur upkeep costs.//
		<</if>>
	<</if>>

__Immigration:__
	<<if $SecExp.edicts.limitImmigration == 1>>

''Immigration limits:'' you put strict limits to the amount of people the arcology can accept each week.
		[[Repeal|edicts][$SecExp.edicts.limitImmigration = 0]]
	<<else>>

''Immigration limits:'' institute limits to the amount of people the arcology will accept each week.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.openBorders = 0, $SecExp.edicts.limitImmigration = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will lower the amount of people immigrating into the arcology and enhance security.//
	<</if>>

	<<if $SecExp.edicts.openBorders == 1>>

''Open borders:'' you have lowered considerably the requirements to become citizens.
		[[Repeal|edicts][$SecExp.edicts.openBorders = 0]]
	<<else>>

''Open borders:'' considerably lower requirements to become citizens.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.openBorders = 1, $SecExp.edicts.limitImmigration = 0, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will increase immigration to the arcology, but will increase crime.//
	<</if>>

__Weapons:__
	<<if $SecExp.edicts.weaponsLaw == 0>>

''Forbid weapons inside the arcology:'' residents are forbidden to buy, sell and keep weaponry while within the arcology.
		[[Repeal|edicts][$SecExp.edicts.weaponsLaw = 3]]
	<<elseif $SecExp.edicts.weaponsLaw == 2>>

''Heavy weaponry forbidden:'' residents are allowed to buy, sell and keep weapons within the arcology as long as they are non-heavy, non-explosive.
		[[Repeal|edicts][$SecExp.edicts.weaponsLaw = 3]]
	<<elseif $SecExp.edicts.weaponsLaw == 1>>

''Heavily restricted weaponry:'' residents are allowed to buy, sell and keep weapons within the arcology as long as they are non-automatic, non-high caliber.
		[[Repeal|edicts][$SecExp.edicts.weaponsLaw = 3]]
	<<else>>

''All weapons allowed:'' residents are allowed to buy, sell and keep all kind of weapons in the arcology.
	<</if>>

	<<if $SecExp.edicts.weaponsLaw == 3>>

''Heavy weaponry forbidden:'' set the range of weapons allowed within the arcology to non-heavy, non-explosive.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.weaponsLaw = 2, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will slightly increase prosperity, but will cost a small amount of authority each week and will leave rebellions decently armed.//
	<<elseif $SecExp.edicts.weaponsLaw == 2>>

''All weapons allowed:'' allow residents of the arcology to buy, sell and keep weaponry of any kind within the arcology.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.weaponsLaw = 3, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will slightly increase prosperity and provide a small weekly amount of reputation, but rebellions will be very well armed.//

''Heavily restricted weaponry:'' set the range of weapons allowed within the arcology to non-automatic, non-high caliber.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.weaponsLaw = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will cost some authority each week, but rebellions will be poorly armed.//
	<<elseif $SecExp.edicts.weaponsLaw == 1>>

''Heavy weaponry forbidden:'' set the range of weapons allowed within the arcology to non-heavy, non-explosive.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.weaponsLaw = 2, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will slightly increase prosperity, but will cost a small amount of authority each week and will leave rebellions decently armed.//

''Forbid weapons inside the arcology:'' forbid residents to buy, sell and keep weaponry while within the arcology.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.weaponsLaw = 0, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will cost a moderate amount of authority each week, but rebellions will be very poorly armed.//
	<<elseif $SecExp.edicts.weaponsLaw == 0>>

''Heavily restricted weaponry:'' set the range of weapons allowed within the arcology to non-automatic, non-high caliber.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.weaponsLaw = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will cost some authority each week, but rebellions will be poorly armed.//
	<</if>>

	<<if $FSAnnounced>>

__Future Societies:__
		<<if $SecExp.edicts.defense.legionTradition === 1>>

''@@.lime;Legionaries traditions:@@'' you are funding specialized training for your recruits following the Roman tradition of professional armies.
			[[Repeal|edicts][$SecExp.edicts.defense.legionTradition = 0]]
		<</if>>
		<<if $SecExp.edicts.defense.imperialTradition === 1>>

''@@.lime;Neo-Imperial traditions:@@'' you are funding specialized training for your recruits to inculcate them into a professional Imperial army, led by highly trained and hand-picked $mercenariesTitle.
			[[Repeal|edicts][$SecExp.edicts.defense.imperialTradition = 0]]
		<</if>>
		<<if $SecExp.edicts.defense.pharaonTradition === 1>>

''@@.lime;Pharaonic traditions:@@'' you are funding specialized training for your recruits to turn them into an army worthy of a pharaon.
			[[Repeal|edicts][$SecExp.edicts.defense.pharaonTradition = 0]]
		<</if>>
		<<if $SecExp.edicts.defense.militia >= 1>>
			<<if $arcologies[0].FSRomanRevivalist >= 40>>
				<<if $SecExp.edicts.defense.legionTradition === 0>>

''@@.lime;Legionaries traditions:@@'' Fund specialized training for your recruits to turn them into the professional of Roman tradition.
					<<if $SecExp.core.authority >= 1000>>
						[[Implement|edicts][$SecExp.edicts.defense.legionTradition = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
					<<else>>

//Not enough Authority.//
					<</if>>

    //Will increase defense, morale and hp of militia units, but will incur upkeep costs.//
				<</if>>
			<</if>>
			<<if $arcologies[0].FSEgyptianRevivalist >= 40>>
				<<if $SecExp.edicts.defense.pharaonTradition === 0>>

''@@.lime;Pharaonic traditions:@@'' Fund specialized training for your recruits to turn them into an army worthy of a pharaoh.
					<<if $SecExp.core.authority >= 1000>>
						[[Implement|edicts][$SecExp.edicts.defense.pharaonTradition = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
					<<else>>

//Not enough Authority.//
					<</if>>

    //Will increase attack, defense and morale of militia units, but will incur upkeep costs.//
				<</if>>
			<</if>>
			<<if $arcologies[0].FSNeoImperialist >= 40>>
				<<if $SecExp.edicts.defense.imperialTradition === 0>>

''@@.lime;Neo-Imperial traditions:@@'' Fund specialized training for your recruits to turn them into a professional Imperial army, led by your handpicked Imperial Knights.
					<<if $SecExp.core.authority >= 1000>>
						[[Implement|edicts][$SecExp.edicts.defense.imperialTradition = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
					<<else>>

//Not enough Authority.//
					<</if>>

    //Will moderately increase  defense, hp, and morale of your militia units and increase attack, defense and morale of your mrecenaries, but will incur upkeep costs.//
				<</if>>
			<</if>>
		<</if>>

		<<if $SecExp.edicts.defense.eagleWarriors === 1>>

''@@.lime;Eagle warriors traditions:@@'' you are funding specialized training for your mercenaries following the Aztec tradition of elite warriors.
			[[Repeal|edicts][$SecExp.edicts.defense.eagleWarriors = 0]]
		<</if>>

		<<if $SecExp.edicts.defense.ronin === 1>>

''@@.lime;Ronin traditions:@@'' you are funding specialized training for your mercenaries following the Japanese tradition of elite errant samurai.
			[[Repeal|edicts][$SecExp.edicts.defense.ronin = 0]]
		<</if>>
		<<if $mercenaries > 0>>
			<<if $arcologies[0].FSAztecRevivalist >= 40>>
				<<if $SecExp.edicts.defense.eagleWarriors === 0>>

''@@.lime;Eagle warriors traditions:@@'' Fund specialized training for your mercenaries to turn them into the elite units of Aztec tradition.
					<<if $SecExp.core.authority >= 1000>>
						[[Implement|edicts][$SecExp.edicts.defense.eagleWarriors = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
					<<else>>

//Not enough Authority.//
					<</if>>

    //Will give a high increase in attack and morale, but will lower defense of mercenary units and will incur upkeep costs.//
				<</if>>
			<</if>>
			<<if $arcologies[0].FSEdoRevivalist >= 40>>
				<<if $SecExp.edicts.defense.ronin === 0>>

''@@.lime;Ronin traditions:@@'' Fund specialized training for your mercenaries to turn them into the errant samurai of Japanese tradition.
					<<if $SecExp.core.authority >= 1000>>
						[[Implement|edicts][$SecExp.edicts.defense.ronin = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
					<<else>>

//Not enough Authority.//
					<</if>>

    //Will increase attack, defense and morale of mercenary units, but will incur upkeep costs.//
				<</if>>
			<</if>>
		<</if>>

		<<if $SecExp.edicts.defense.mamluks === 1>>

''@@.lime;Mamluks traditions:@@'' you are funding specialized training for your slaves following the Arabian tradition of mamluks slave soldiers.
			[[Repeal|edicts][$SecExp.edicts.defense.mamluks = 0]]
		<</if>>

		<<if $SecExp.edicts.defense.sunTzu === 1>>

''@@.lime;Sun Tzu Teachings:@@'' you are funding specialized training for your units and officers to follow the teachings of the "Art of War".
			[[Repeal|edicts][$SecExp.edicts.defense.sunTzu = 0]]
		<</if>>
		<<if $arcologies[0].FSArabianRevivalist >= 40>>
			<<if $SecExp.edicts.defense.mamluks === 0>>

''@@.lime;Mamluks traditions:@@'' Fund specialized training for your slaves to turn them into the mamluks slave soldiers of Arabian tradition.
				<<if $SecExp.core.authority >= 1000>>
					[[Implement|edicts][$SecExp.edicts.defense.mamluks = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
				<<else>>

//Not enough Authority.//
				<</if>>

    //Will increase attack, morale and hp of slave units, but will incur upkeep costs.//
			<</if>>
		<</if>>
		<<if $arcologies[0].FSChineseRevivalist >= 40>>
			<<if $SecExp.edicts.defense.sunTzu === 0>>

''@@.lime;Sun Tzu Teachings:@@'' Fund specialized training for your units and officers to conform your army to the teachings of the "Art of War".
				<<if $SecExp.core.authority >= 1000>>
					[[Implement|edicts][$SecExp.edicts.defense.sunTzu = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
				<<else>>

//Not enough Authority.//
				<</if>>

    //Will slightly increase attack, defense and morale of all units, but will incur upkeep costs.//
			<</if>>
		<</if>>
	<</if>>

	<<if $SecExp.edicts.defense.soldierWages === 0>>

''Low wages for soldiers:'' wages for soldiers are set to a low level compared to market standards.
		[[Repeal|edicts][$SecExp.edicts.defense.soldierWages = 1]]
	<<elseif $SecExp.edicts.defense.soldierWages === 1>>

''Average wages for soldiers:'' wages for soldiers are set to the market standards.
	<<else>>

''High wages for soldiers:'' wages for soldiers are set to a high level compared to market standards.
		[[Repeal|edicts][$SecExp.edicts.defense.soldierWages = 1]]
	<</if>>

	<<if $SecExp.edicts.defense.soldierWages === 0>>

''Average wages for soldiers:'' will set the wages paid to the soldiers of the arcology to an average amount.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.defense.soldierWages += 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will raise all units upkeep and push loyalty to average levels.//
	<<elseif $SecExp.edicts.defense.soldierWages === 1>>

''Low wages for soldiers:'' will set the wages paid to the soldiers of the arcology to a low amount.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.defense.soldierWages -= 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will lower all units upkeep and push loyalty to low levels.//

''High wages for soldiers:'' will set the wages paid to the soldiers of the arcology to a high amount.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.defense.soldierWages += 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will raise all units upkeep and push loyalty to high levels.//
	<<else>>

''Average wages for soldiers:'' will set the wages paid to the soldiers of the arcology to an average amount.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.defense.soldierWages -= 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will lower all units upkeep and push loyalty to average levels.//
	<</if>>

	<<if $SecExp.edicts.defense.slavesOfficers === 1>>

''Slave Officers:'' your trusted slaves are allowed to lead the defense forces of the arcology.
		[[Repeal|edicts][$SecExp.edicts.defense.slavesOfficers = 0]]
	<<else>>

''Slave Officers:'' allow your trusted slaves to lead the defense forces of the arcology.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.defense.slavesOfficers = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will allow your bodyguard and Head Girl to lead troops into battle, but will cost a small amount of authority each week.//
	<</if>>

	<<if $mercenaries > 0>>
		<<if $SecExp.edicts.defense.discountMercenaries === 1>>

''Mercenary subsidy:'' mercenaries willing to immigrate in your arcology will be offered a discount on rent.
			[[Repeal|edicts][$SecExp.edicts.defense.discountMercenaries = 0]]
		<<else>>

''Mercenary subsidy:'' mercenaries willing to immigrate in your arcology will be offered a discount on rent.
			<<if $SecExp.core.authority >= 1000>>
				[[Implement|edicts][$SecExp.edicts.defense.discountMercenaries = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
			<<else>>

//Not enough Authority.//
			<</if>>

    //Will slightly lower rent, but will increase the amount of available mercenaries.//
		<</if>>
	<</if>>

	<<if $SecExp.edicts.defense.militia === 0>>

''Found the militia:'' lay the groundwork for the formation of the arcology's citizens' army.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.defense.militia = 2, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will allow for the recruitment and training of citizens.//
	<<else>>
		<<if $SecExp.edicts.defense.militia === 1>>

''Volunteers' militia:'' only volunteers will be accepted in the militia.
			<<if $SecExp.core.authority >= 1000>>
				[[Implement|edicts][$SecExp.edicts.defense.militia = 2, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
			<<else>>

//Not enough Authority.//
			<</if>>

    //Will replenish militia manpower slowly and will cap at <<= num(App.SecExp.militiaCap(2)*100)>>% of the total citizens population.//
		<</if>>

		<<if $SecExp.edicts.defense.militia === 3>>

''Conscription:'' every citizen is required to train in the militia and serve the arcology for a limited amount of time.
			[[Repeal|edicts][$SecExp.edicts.defense.militia = 2]]
		<<else>>

''Conscription:'' every citizen is required to train in the militia and serve the arcology if the need arises.
			<<if $SecExp.core.authority >= 4000>>
				[[Implement|edicts][$SecExp.edicts.defense.militia = 3, cashX(-5000, "edicts"), $SecExp.core.authority -= 4000]]
			<<else>>

//Not enough Authority.//
			<</if>>

    //Will replenish militia manpower moderately fast and will cap at <<= num(App.SecExp.militiaCap(3)*100)>>% of the total citizens population, but has a high authority cost//
		<</if>>
		<<if $SecExp.edicts.defense.militia === 4>>

''Obligatory military service:'' every citizen is required to register and serve under the militia.
			[[Repeal|edicts][$SecExp.edicts.defense.militia = 2]]
		<<else>>

''Obligatory military service:'' every citizen is required to register and serve under the militia.
			<<if $SecExp.core.authority >= 6000>>
				[[Implement|edicts][$SecExp.edicts.defense.militia = 4, cashX(-5000, "edicts"), $SecExp.core.authority -= 6000]]
			<<else>>

//Not enough Authority.//
			<</if>>

    //Will quickly replenish militia manpower and will cap at <<= num(App.SecExp.militiaCap(4)*100)>>% of the total citizens population, but has a very high authority cost//
		<</if>>
		<<if $SecExp.edicts.defense.militia === 5>>

''Militarized Society:'' every adult citizen is required to train and actively participate in the military of the arcology.
			[[Repeal|edicts][$SecExp.edicts.defense.militia = 2]]
		<<else>>

''Militarized Society:'' every adult citizen is required to train and participate in the defense of the arcology.
			<<if $SecExp.core.authority >= 8000>>
				[[Implement|edicts][$SecExp.edicts.defense.militia = 5, cashX(-5000, "edicts"), $SecExp.core.authority -= 8000]]
			<<else>>

//Not enough Authority.//
			<</if>>

    //Will very quickly replenish militia manpower and will cap at <<= num(App.SecExp.militiaCap(5)*100)>>% of the total citizens population, but has an extremely high authority cost//
		<</if>>

		<<if $SecExp.edicts.defense.militaryExemption === 1>>

''Military exemption:'' you allow citizens to avoid military duty by paying a weekly fee.
				[[Repeal|edicts][$SecExp.edicts.defense.militaryExemption = 0]]
		<</if>>
		<<if $SecExp.edicts.defense.militia >= 3>>
			<<if $SecExp.edicts.defense.militaryExemption === 0>>

''Military exemption:'' allow citizens to avoid military duty by paying a weekly fee.
				<<if $SecExp.core.authority >= 1000>>
					[[Implement|edicts][$SecExp.edicts.defense.militaryExemption = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
				<<else>>

//Not enough Authority.//
				<</if>>

    //Will slow down the replenishment of manpower, but will supply cash each week. More profitable with stricter recruitment laws.//
			<</if>>
		<</if>>

		<<if $SecExp.edicts.defense.lowerRequirements == 1>>

''@@.lime;Revised minimum requirements:@@'' you allow citizens outside the normally accepted range to join the militia.
			[[Repeal|edicts][$SecExp.edicts.defense.lowerRequirements = 0]]
		<</if>>
		<<if $arcologies[0].FSHedonisticDecadence >= 40>>
			<<if $SecExp.edicts.defense.lowerRequirements == 0>>

''@@.lime;Revised minimum requirements:@@'' will allow citizens outside the normally accepted range to join the militia.
				<<if $SecExp.core.authority >= 1000>>
					[[Implement|edicts][$SecExp.edicts.defense.lowerRequirements = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
				<<else>>

//Not enough Authority.//
				<</if>>

    //Will slightly lower defense and hp of militia units, but will increase the manpower replenishment rate.//
			<</if>>
		<</if>>

		<<if $SecExp.edicts.defense.noSubhumansInArmy == 1>>

''@@.lime;No subhumans in the militia:@@'' it is forbidden for subhumans to join the militia.
			[[Repeal|edicts][$SecExp.edicts.defense.noSubhumansInArmy = 0]]
		<</if>>
		<<if $arcologies[0].FSSubjugationist >= 40>>
			<<if $SecExp.edicts.defense.noSubhumansInArmy == 0>>

''@@.lime;No subhumans in the militia:@@'' prevent subhumans from joining the militia.
				<<if $SecExp.core.authority >= 1000>>
					[[Implement|edicts][$SecExp.edicts.defense.noSubhumansInArmy = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
				<<else>>

//Not enough Authority.//
				<</if>>

    //Will help advance racial Subjugation, but will slow down slightly manpower replenishment.//
			<</if>>
		<</if>>

		<<if $SecExp.edicts.defense.pregExemption == 1>>

''@@.lime;Military exemption for pregnancies:@@'' pregnant citizens are allowed, and encouraged, to avoid military service.
			[[Repeal|edicts][$SecExp.edicts.defense.pregExemption = 0]]
		<</if>>
		<<if $arcologies[0].FSRepopulationFocus >= 40 && $SecExp.edicts.defense.militia >= 3>>
			<<if $SecExp.edicts.defense.pregExemption == 0>>

''@@.lime;Military exemption for pregnancies:@@'' pregnant citizens will be allowed, and encouraged, to avoid military service.
				<<if $SecExp.core.authority >= 1000>>
					[[Implement|edicts][$SecExp.edicts.defense.pregExemption = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
				<<else>>

//Not enough Authority.//
				<</if>>

    //Will help advance repopulation focus, but will slow down slightly manpower replenishment.//
			<</if>>
		<</if>>
	<</if>>

	<<if $SecExp.edicts.defense.privilege.militiaSoldier === 1>>

''Special militia privileges:'' citizens joining the militia are exempt from rent payment.
		[[Repeal|edicts][$SecExp.edicts.defense.privilege.militiaSoldier = 0]]
	<</if>>
	<<if $SecExp.edicts.defense.privilege.militiaSoldier === 0 && $SecExp.edicts.defense.militia >= 1>>

''Special militia privileges'' will allow citizens joining the militia to avoid paying rent.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.defense.privilege.militiaSoldier = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will increase the loyalty of militia units, but will decrease rents.//
	<</if>>

	<<if $SecExp.edicts.defense.privilege.slaveSoldier === 1>>

''Special slaves privileges:'' Slaves into the army are allowed to have material possessions.
		[[Repeal|edicts][$SecExp.edicts.defense.privilege.slaveSoldier = 0]]
	<</if>>
	<<if $SecExp.edicts.defense.privilege.slaveSoldier === 0>>

''Special slaves privileges'' will allow slaves drafted into the army to be able to have material possessions.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.defense.privilege.slaveSoldier = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will increase the loyalty of slave units, but will cost authority each week.//
	<</if>>

	<<if $SecExp.edicts.defense.privilege.mercSoldier === 1>>

''Special mercenary privileges:'' Mercenaries under contract can claim part of the loot gained from battles.
		[[Repeal|edicts][$SecExp.edicts.defense.privilege.mercSoldier = 0]]
	<</if>>
	<<if $SecExp.edicts.defense.privilege.mercSoldier === 0 && $mercenaries > 0>>

''Special mercenary privileges'' will allow mercenaries under contract to claim part of the loot gained from battles.
		<<if $SecExp.core.authority >= 1000>>
			[[Implement|edicts][$SecExp.edicts.defense.privilege.mercSoldier = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
		<<else>>

//Not enough Authority.//
		<</if>>

    //Will increase the loyalty of mercenary units, but will reduce cash and menial slaves gained from battles.//
	<</if>>

	<<if $SecExp.edicts.defense.martialSchool === 1>>

''@@.lime;Slave martial schools:@@'' specialized schools are training slaves in martial arts and bodyguarding.
		[[Repeal|edicts][$SecExp.edicts.defense.martialSchool = 0]]
	<</if>>
	<<if $arcologies[0].FSPhysicalIdealist >= 40>>
		<<if $SecExp.edicts.defense.martialSchool === 0>>

''@@.lime;Slave martial schools:@@'' specialized schools will be set up to train slaves in martial arts and bodyguarding.
			<<if $SecExp.core.authority >= 1000>>
				[[Implement|edicts][$SecExp.edicts.defense.martialSchool = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
			<<else>>

//Not enough Authority.//
			<</if>>

    //Will slightly increase morale of slave units, but will incur upkeep costs.//
		<</if>>
	<</if>>

	<<if $SecExp.edicts.defense.eliteOfficers === 1>>

''@@.lime;Elite officers:@@'' officers are exclusively recruited from the elite of society.
		[[Repeal|edicts][$SecExp.edicts.defense.eliteOfficers = 0]]
	<</if>>
	<<if $arcologies[0].FSRestart >= 40>>
		<<if $SecExp.edicts.defense.eliteOfficers === 0>>

''@@.lime;Elite officers:@@'' officers will be exclusively recruited from the elite of society.
			<<if $SecExp.core.authority >= 1000>>
				[[Implement|edicts][$SecExp.edicts.defense.eliteOfficers = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
			<<else>>

//Not enough Authority.//
			<</if>>

    //Will help advance eugenics and provide a small morale boost to militia units, but will give a small morale malus to slave units.//
		<</if>>
	<</if>>

	<<if $SecExp.edicts.defense.liveTargets === 1>>

''@@.lime;Live targets drills:@@'' disobedient slaves are used as live targets at shooting ranges.
		[[Repeal|edicts][$SecExp.edicts.defense.liveTargets = 0]]
	<</if>>
	<<if $arcologies[0].FSDegradationist >= 40>>
		<<if $SecExp.edicts.defense.liveTargets === 0>>

''@@.lime;Live targets drills:@@'' disobedient slaves will be used as live targets at shooting ranges.
			<<if $SecExp.core.authority >= 1000>>
				[[Implement|edicts][$SecExp.edicts.defense.liveTargets = 1, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
			<<else>>

//Not enough Authority.//
			<</if>>

    //Will help advance degradationism and provide a small amount of exp to units, but will make the slave population slowly decline.//
		<</if>>
	<</if>>

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

__Special Force:__
		<<set _capSF = capFirstChar($SF.Lower || "the special force")>>
		<<if $SecExp.edicts.SFSupportLevel > 0>>
			<<if $SecExp.edicts.SFSupportLevel === 1>>

''Equipment provision:'' _capSF is providing the security HQ with advanced equipment, boosting its efficiency.
			<<elseif $SecExp.edicts.SFSupportLevel === 2>>

''Personnel training:'' _capSF is currently providing advanced equipment and training to security HQ personnel.
			<<elseif $SecExp.edicts.SFSupportLevel === 3>>

''Troops detachment:'' _capSF has currently transferred troops to the security department HQ in addition to providing advanced equipment and training to security HQ personnel.
			<<elseif $SecExp.edicts.SFSupportLevel === 4>>

''Full support:'' _capSF is currently providing its full support to the security department, while transferring troops to the security department HQ in addition to providing advanced equipment and training to security HQ personnel.
			<<elseif $SecExp.edicts.SFSupportLevel === 5>>

''Network assistance:'' _capSF is currently assisting with a local install of its custom network full support and has transferred troops to the security department HQ in addition to providing advanced equipment and training to security HQ personnel.
			<</if>>
			[[Repeal|edicts][$SecExp.edicts.SFSupportLevel--]]
		<</if>>
		<<if $SecExp.edicts.SFSupportLevel < 5>>
			<<if $SecExp.edicts.SFSupportLevel === 0 && App.SecExp.Check.reqMenials() > 5>>

''Equipment provision:'' _capSF will provide the security HQ with advanced equipment.

    //Will lower the amount of personnel necessary to man the security HQ by 5, but will incur upkeep costs.//
			<<elseif $SecExp.edicts.SFSupportLevel === 1 && $SF.Squad.Firebase >= 4 && App.SecExp.Check.reqMenials() > 5>>

''Personnel training:'' _capSF will provide the security HQ personnel with advanced training.

    //Will lower the amount of personnel necessary to man the security HQ by a further 5, but will incur additional upkeep costs.//
			<<elseif $SecExp.edicts.SFSupportLevel === 2 && $SF.Squad.Firebase >= 6 && App.SecExp.Check.reqMenials() > 5>>

''Troops detachment:'' _capSF will provide troops to the security department.

    //Will lower the amount of personnel necessary to man the security HQ by a further 5, but will incur additional upkeep costs.//
			<<elseif $SecExp.edicts.SFSupportLevel === 3 && $SF.Squad.Firebase >= 6 && App.SecExp.Check.reqMenials() > 5>>

''Full Support:'' _capSF will give the security department its full support.

    //Will lower the amount of personnel necessary to man the security HQ by a further 5, but will incur additional upkeep costs.//
			<<elseif $SecExp.edicts.SFSupportLevel === 4 && $SF.Squad.Firebase === 10 && App.SecExp.Check.reqMenials() > 5>>

''Network assistance:'' _capSF will assist the security department with installing a local version of their custom network.

    //Will lower the amount of personnel necessary to man the security HQ by a further 5, but will incur additional upkeep costs.//
			<</if>>
			<<if $SecExp.core.authority >= 1000>>
				[[Implement|edicts][$SecExp.edicts.SFSupportLevel++, cashX(-5000, "edicts"), $SecExp.core.authority -= 1000]]
			<<else>>

//Not enough Authority.//
			<</if>>
		<</if>>
	<</if>>

repo_name: Welptard/fc

license: mit


code:
/** Creates a bulk upgrade link for the unit that is passed.
 * @param {object} [unit] the unit to be checked.
 */
App.SecExp.bulkUpgradeUnit = function(unit) {
	unit = Array.isArray(unit) ? unit : [unit];
	let el = document.createElement("a");

	function upgradeUnit(x) {
		Object.assign(x, {
			maxTroops: 50, equip: 3, commissars: 2,
			cyber: 1, medics: 1, SF: 1
		});
	}

	function getCost(x) {
		let cost = 0;
		const equipUpgradeCost = 250;
		if (x.maxTroops < 50) {
			cost += 5000 + (((50 - x.maxTroops) /10) * equipUpgradeCost * (x.equip + x.commissars + x.cyber + x.SF));
		}
		if (x.equip < 3) {
			cost += (equipUpgradeCost * x.maxTroops + 1000) * (3 - x.equip);
		}
		if (x.commissars < 2) {
			cost += (equipUpgradeCost * x.maxTroops + 1000) * (2 - x.commissars);
		}
		if ((V.prostheticsUpgrade >= 2 || V.researchLab.advCombatPLimb === 1) && x.cyber === 0) {
			cost += equipUpgradeCost * x.maxTroops + 2000;
		}
		if (x.medics === 0) {
			cost += equipUpgradeCost * x.maxTroops + 1000;
		}
		if (V.SF.Toggle && V.SF.Active >= 1 && x.SF === 0) {
			cost += equipUpgradeCost * x.maxTroops + 5000;
		}
		return Math.ceil(cost *= 1.1);
	}

	const price = unit.map(getCost).reduce((acc, cur) => acc + cur, 0);
	if (price > 0) {
		el.append(App.UI.DOM.link(`Bulk upgrade for ${cashFormat(price)}`, () => {
			unit.map(upgradeUnit).reduce((acc, cur) => acc + cur);
			cashX(-price, "securityExpansion");
		},
		[], passage()
		));
	}
	return el;
};

/** Reports changes to the supplied unit's loyalty.
 * @param {FC.SecExp.PlayerHumanUnitData} input the unit type to be checked.
 * @param {FC.SecExp.PlayerHumanUnitType} type
 */
App.SecExp.humanUnitLoyaltyChanges = function(input, type) {
	let loyaltyChange = 0, el = document.createElement("div");

	el.append(`${input.platoonName}: `);
	if (V.SecExp.buildings.barracks && V.SecExp.buildings.barracks.loyaltyMod >= 1) {
		el.append("is periodically sent to the indoctrination facility in the barracks for thought correction therapy.");
		loyaltyChange += 2 * V.SecExp.buildings.barracks.loyaltyMod;
	}
	if (input.commissars >= 1) {
		el.append("The commissars attached to the unit carefully monitor the officers and grunts for signs of insubordination.");
		loyaltyChange += 2 * input.commissars;
	}
	if (V.SecExp.edicts.defense.soldierWages === 2) {
		if (type === 'slave') {
			el.append("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.");
		} else if (type === 'citizens') {
			el.append("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.");
		} else if (type === 'mercenary') {
			el.append("The mercenaries greatly appreciate the generous wage given to them for their service. After all coin is the fastest way to reach their hearts.");
		}
		loyaltyChange += random(5, 10);
	} else if (V.SecExp.edicts.defense.soldierWages === 1) {
		if (type === 'slave') {
			el.append("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.");
		} else if (type === 'citizens') {
			el.append("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.");
		} else if (type === 'mercenary') {
			el.append("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.");
		}
		loyaltyChange += random(-5, 5);
	} else {
		if (type === 'slave') {
			el.append("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.");
		} else if (type === 'citizens') {
			el.append("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.");
		} else if (type === 'mercenary') {
			el.append("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.");
		}
		loyaltyChange -= random(5, 10);
	}
	if (type === 'slave' && V.SecExp.edicts.defense.privilege.slaveSoldier) {
		el.append("Allowing them to hold material possessions earns you their devotion and loyalty.");
		loyaltyChange += random(1, 2);
	}
	if (type === 'citizens' && V.SecExp.edicts.defense.privilege.militiaSoldier) {
		el.append("Allowing them to avoid rent payment for their military service earns you their happiness and loyalty.");
		loyaltyChange += random(1, 2);
	}
	if (type === 'mercenary' && V.SecExp.edicts.defense.privilege.mercSoldier) {
		el.append("Allowing them to keep part of the loot gained from your enemies earns you their trust and loyalty.");
		loyaltyChange += random(1, 2);
	}

	el.append("This week, the loyalty of this unit ");
	if (loyaltyChange > 0) {
		 App.UI.DOM.appendNewElement("span", el, "increased.", "green");
	} else if (loyaltyChange === 0) {
		App.UI.DOM.appendNewElement("span", el, "did not change.", "yellow");
	} else {
		App.UI.DOM.appendNewElement("span", el, "decreased.", "red");
	}
	input.loyalty = Math.clamp(input.loyalty + loyaltyChange, 0, 100);
	if (input.training < 100 && V.SecExp.buildings && V.SecExp.buildings.barracks.training >= 1) {
		let options = document.createElement("div");
		options.append("The unit is able to make use of the training facilities to better prepare its soldiers, slowly increasing their experience level.");
		el.append(options);
		input.training += random(2, 4) * 1.5 * V.SecExp.buildings.barracks.training;
	}

	return el;
};

/** Repairs unit if needed.
 * @param {object} [input] the unit to be checked.
 */
App.SecExp.fixBrokenUnit = function(input) {
	input.SF = input.SF || 0;
	if (!jsDef(input.ID)) {
		input.ID = App.SecExp.generateUnitID();
	}
	input.cyber = input.cyber || 0;
	input.commissars = input.commissars || 0;
	input.maxTroops = Math.min(30, input.maxTroops);
	Math.clamp(input.troops, 0, input.maxTroops);
};

/** Creates the requested unit object.
 * @param {string} [type] the unit type to be created.
 */
App.SecExp.generateUnit = function(type) {
	let newUnit = {
		ID: -1, equip: 0, active: 1, isDeployed: 0, maxTroops:30,  troops: 30
	};
	if (type !== "bots") {
		Object.assign(newUnit, {
			training: 0, cyber: 0, medics: 0,
			SF: 0, commissars: 0, battlesFought: 0,
			loyalty: jsRandom(40, 60),
			ID: App.SecExp.generateUnitID()
		});

		if (type === "slaves") {
			newUnit.platoonName = `${ordinalSuffix(++V.createdSlavesUnits)} ` + V.SecExp.defaultNames[type];
			newUnit.troops = Math.min(newUnit.maxTroops, V.menials);
			V.menials -= newUnit.troops;
		} else if (type === "militia") {
			newUnit.platoonName = `${ordinalSuffix(++V.createdMilitiaUnits)} ` + V.SecExp.defaultNames[type];
			newUnit.troops = Math.min(newUnit.maxTroops, V.militiaFreeManpower);
			V.militiaFreeManpower -= newUnit.troops;
		} else if (type === "mercs") {
			newUnit.platoonName = `${ordinalSuffix(++V.createdMercUnits)} ` + V.SecExp.defaultNames[type];
			newUnit.troops = Math.min(newUnit.maxTroops, V.mercFreeManpower);
			V.mercFreeManpower -= newUnit.troops;
		}
	}
	return newUnit;
};

/** Display's the deploy menu for the unit.
 * @param {FC.SecExp.PlayerHumanUnitData} input the unit to be checked.
 * @param {FC.SecExp.PlayerHumanUnitType} type
 * @param {number} [count=0]
 */
App.SecExp.deployUnitMenu = function(input, type, count = 0) {
	let el = document.createElement("div"), options = document.createElement("div");
	const canDeploy = input.isDeployed === 0 && App.SecExp.battle.deployableUnits() > 0;

	if (input.active === 1 && input.troops > 0) {
		if (type === "bots") {
			$(el).append(App.SecExp.getUnit("Bots").describe());
		} else {
			$(el).append(App.SecExp.getUnit(capFirstChar(type), count).describe());
		}
		options = document.createElement("div");
		options.append(App.UI.DOM.link(`${canDeploy ? 'Deploy' : 'Remove'} the unit`, () => {
			input.isDeployed = canDeploy ? 1 : 0; V.saveValid = 0;
		},
		[], passage()
		));
	}
	el.append(options);
	return el;
};

/** Prints a list of upgrades that can be applied to the passed human unit.
 * @param {FC.SecExp.PlayerHumanUnitData} input the human unit to be checked.
 */
App.SecExp.humanUnitUpgradeList = function(input) {
	const equipUpgradeCost = 250;
	let el = document.createElement("div"); let options = document.createElement("div");

	if (input.maxTroops < 50) {
		options.append(`For ${cashFormat(5000 + 10 * equipUpgradeCost * (input.equip + input.commissars + input.cyber + input.SF))} provide this unit's `);
		options.append(App.UI.DOM.link("officers with intensive training", () => {
			input.maxTroops += 10;
			cashX(-(5000 + 10 * equipUpgradeCost * (input.equip + input.commissars + input.cyber + input.SF)), "securityExpansion");
		},
		[], passage()
		));
		options.append(` to increase the maximum number of soldiers in the unit by 10.`);
	} else {
		options.append(`Your officers reached their peak. Further training will have little impact on the number of troops they can effectively lead.`);
	}
	el.append(options);

	options = document.createElement("div");
	if (input.equip < 3) {
		options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 1000)} invest in `);
		options.append(App.UI.DOM.link("better equipment", () => {
			input.equip++;
			cashX(-(equipUpgradeCost * input.maxTroops + 1000), "securityExpansion");
		},
		[], passage()
		));
		options.append(` to increase this unit's attack and defense by 15% per investement.`);
	} else {
		options.append(`The unit is equipped with state of the art weaponry and equipment.`);
	}
	el.append(options);

	options = document.createElement("div");
	if (input.commissars === 0) {
		options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 1000)} attach `);
		options.append(App.UI.DOM.link("commissars", () => {
			input.commissars++;
			cashX(-(equipUpgradeCost * input.maxTroops + 1000), "securityExpansion");
		},
		[], passage()
		));
		options.append(` to slowly increase this unit's loyalty.`);
	} else if (input.commissars < 2) {
		options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 1000)} attach `);
		options.append(App.UI.DOM.link("commissars", () => {
			input.commissars++;
			cashX(-(equipUpgradeCost * input.maxTroops + 1000), "securityExpansion");
		},
		[], passage()
		));
		options.append(` to slowly increase this unit's loyalty.`);
	}
	if (input.commissars === 1) {
		options.append(" The unit has a commissar detachment, keeping under control the ambitions of the unit's officers.");
	} else if (input.commissars === 2) {
		options.append(" The unit has a perfectly trained and loyal commissar detachment, keeping under control the ambitions of the unit's officers.");
	}
	el.append(options);

	options = document.createElement("div");
	if (V.prostheticsUpgrade >= 2 || V.researchLab.advCombatPLimb === 1) {
		if (input.cyber === 0) {
			options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 1000)} `);
			options.append(App.UI.DOM.link("augment all soldiers of the unit", () => {
				input.cyber++;
				cashX(-(equipUpgradeCost * input.maxTroops + 2000), "securityExpansion");
			},
			[], passage()
			));
			options.append(` with high tech cyber enhancements that will increase attack, defense and base hp values.`);
		} else {
			options.append('The unit is equipped with advanced cybernetic enhancements.');
		}
	}
	el.append(options);

	options = document.createElement("div");
	if (input.medics === 0) {
		options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 1000)} `);
		options.append(App.UI.DOM.link("attach trained medics to the unit", () => {
			input.medics++;
			cashX(-(equipUpgradeCost * input.maxTroops + 1000), "securityExpansion");
		},
		[], passage()
		));
		options.append(' which will decrease the number of casualties suffered during battle.');
	} else {
		options.append('The unit has a medic detachment following it into battle, decreasing the number of casualties the unit suffers');
	}
	el.append(options);

	if (V.SF.Toggle && V.SF.Active >= 1) {
		options = document.createElement("div");

		if (input.SF === 0) {
			options.append(`For ${cashFormat(equipUpgradeCost * input.maxTroops + 5000)} `);
			options.append(App.UI.DOM.link("attach Special Force advisors", () => {
				input.SF++;
				cashX(-(equipUpgradeCost * input.maxTroops + 5000), "securityExpansion");
			},
			[], passage()
			));
			options.append(' which will slightly increase the base stats of the unit.');
		} else {
			options.append(`The unit has attached advisors from ${V.SF.Lower} that will help the squad remain tactically aware and active.`);
		}
		el.append(options);
	}

	return el;
};

/** Generate a unit ID for a new unit
 * @returns {number}
 */
App.SecExp.generateUnitID = function() {
	return Math.max(
		V.militiaUnits.reduce((acc, cur) => Math.max(acc, cur.ID), 0),
		V.slaveUnits.reduce((acc, cur) => Math.max(acc, cur.ID), 0),
		V.mercUnits.reduce((acc, cur) => Math.max(acc, cur.ID), 0)
	) + 1;
};

/** Player unit factory - get a unit based on its type and index
 * @param {string} type - "Bots", "Militia", "Slaves", "Mercs", or "SF"
 * @param {number} [index] - must be supplied if type is not "Bots"
 * @returns {App.SecExp.Unit}
 */
App.SecExp.getUnit = function(type, index) {
	if (type === "Bots") {
		return new App.SecExp.DroneUnit(V.secBots, App.SecExp.BaseDroneUnit);
	} else if (type === "SF") {
		return new App.SecExp.SFUnit();
	} else if (typeof index !== "number") {
		throw `Bad index for unit type ${type}: ${index}`;
	}

	switch (type) {
		case "Militia":
			return new App.SecExp.HumanUnit(V.militiaUnits[index], App.SecExp.BaseMilitiaUnit, type);
		case "Slaves":
			return new App.SecExp.HumanUnit(V.slaveUnits[index], App.SecExp.BaseSlaveUnit, type);
		case "Mercs":
			return new App.SecExp.HumanUnit(V.mercUnits[index], App.SecExp.BaseMercUnit, type);
		default:
			throw `Unknown unit type: ${type}`;
	}
};

/** Enemy unit factory - get a unit based on its type and basic data
 * @param {FC.SecExp.EnemyUnitType} type - "raiders", "free city", "old world", or "freedom fighters"
 * @param {number} troops
 * @param {number} equipment
 * @returns {App.SecExp.Unit}
 */
App.SecExp.getEnemyUnit = function(type, troops, equipment) {
	const baseUnitMap = new Map([
		["raiders", App.SecExp.BaseRaiderUnit],
		["free city", App.SecExp.BaseFreeCityUnit],
		["old world", App.SecExp.BaseOldWorldUnit],
		["freedom fighters", App.SecExp.BaseFreedomFighterUnit],
	]);
	const unitData = {
		troops: troops,
		maxTroops: troops,
		equip: equipment
	};
	return new App.SecExp.EnemyUnit(unitData, baseUnitMap.get(type));
};

/** Irregular unit factory - get an irregular unit (without organization/upgrade bonuses) based on its type and basic data
 * @param {string} type - "Militia", "Slaves", or "Mercs"
 * @param {number} troops
 * @param {number} equipment
 * @returns {App.SecExp.Unit}
 */
App.SecExp.getIrregularUnit = function(type, troops, equipment) {
	const baseUnitMap = new Map([
		["Militia", App.SecExp.BaseMilitiaUnit],
		["Slaves", App.SecExp.BaseSlaveUnit],
		["Mercs", App.SecExp.BaseMercUnit],
	]);
	const unitData = {
		troops: troops,
		maxTroops: troops,
		equip: equipment
	};

	return new App.SecExp.IrregularUnit(unitData, baseUnitMap.get(type));
};

/** Equipment multiplier (static balance variable) */
App.SecExp.equipMod = 0.15;

/** Turn a loyalty value into a corresponding bonus factor
 * @param {number} value range: [0-100]
 * @returns {number} bonus - range: [0.0-0.3], cap at input 67
 */
App.SecExp.loyaltyValueToBonusFactor = function(value) {
	return Math.min(value * 3 / 670, 0.3);
};

/** Turn a training value into a corresponding bonus factor
 * @param {number} value range: [0-100]
 * @returns {number} bonus - range: [0.0-0.5], cap at input 67
 */
App.SecExp.trainingValueToBonusFactor = function(value) {
	return Math.min(value * 3 / 400, 0.5);
};

/** Gets the bonus values provided for completing weapon manufacturing upgrades.
 * @param {string} type - unit type to check.
 * @returns {object} bouns values after checking for completed upgrades.
 */
App.SecExp.getAppliedUpgrades = function(type) {
	let hp = 0, morale = 0, def = 0, attack = 0;
	if (V.SecExp.buildings.weapManu) {
		if (type === 'drone') {
			if (V.SecExp.buildings.weapManu.upgrades.completed.includes(-3)) {
				hp++;
			}
			if (V.SecExp.buildings.weapManu.upgrades.completed.includes(-2)) {
				def++;
			}
			if (V.SecExp.buildings.weapManu.upgrades.completed.includes(-1)) {
				attack++;
			}
		} else if (type === 'human') {
			if (V.SecExp.buildings.weapManu.upgrades.completed.includes(0)) {
				attack++;
			}
			if (V.SecExp.buildings.weapManu.upgrades.completed.includes(1)) {
				def++;
			}
			if (V.SecExp.buildings.weapManu.upgrades.completed.includes(2)) {
				hp++;
			}
			if (V.SecExp.buildings.weapManu.upgrades.completed.includes(3)) {
				morale += 10;
			}
			if (V.SecExp.buildings.weapManu.upgrades.completed.includes(4)) {
				attack++; def++;
			}
			if (V.SecExp.buildings.weapManu.upgrades.completed.includes(5)) {
				hp++; morale += 10;
			}
			if (V.SecExp.buildings.weapManu.upgrades.completed.includes(6)) {
				attack++; def++;
			}
			if (V.SecExp.buildings.weapManu.upgrades.completed.includes(7)) {
				hp++; morale += 10;
			}
			if (V.SecExp.buildings.weapManu.upgrades.completed.includes(8)) {
				attack++; def++; hp++; morale += 10;
			}
			if (V.arcologies[0].FSNeoImperialistLaw1) {
 				attack++;
			}
		}
	}
	return {
		attack: attack, defense: def, hp: hp, morale: morale
	};
};

App.SecExp.getEdictUpgradeVal = (function() {
	const data = {
		Militia: new Map([
			["legionTradition", {defense: 2, morale: 5, hp: 1}],
			["imperialTradition", {defense: 1, morale: 5, hp: 1}],
			["pharaonTradition", {attack: 2, defense: 2, morale: 10}],
			["sunTzu", {attack: 1, defense: 1, morale: 5}],
			["eliteOfficers", {morale: 5}],
			["lowerRequirements", {defense: -1, hp: -1}]
		]),
		Slave: new Map([
			["mamluks", {attack: 2, morale: 10, hp: 1}],
			["sunTzu", {attack: 1, defense: 1, morale: 5}],
			["eliteOfficers", {morale: -5}],
			["martialSchool", {morale: 5}]
		]),
		Merc: new Map([
			["eagleWarriors", {attack: 4, defense: -2, morale: 10}],
			["ronin", {attack: 2, defense: 2, morale: 10}],
			["sunTzu", {attack: 1, defense: 1, morale: 5}],
			["imperialTradition", {attack: 1, defense: 2, morale: 5}],
		])
	};

	/** Get the total edict upgrade effect on a particular stat for a particular unit
	 * @param {string} unitType
	 * @param {string} stat
	 * @returns {number}
	 */
	function getNetEffect(unitType, stat) {
		let retval = 0;
		for (const [key, val] of data[unitType]) {
			if (V.SecExp.edicts.defense[key] > 0 && val[stat]) {
				retval += val[stat];
			}
		}
		return retval;
	}

	return getNetEffect;
})();

/**
 * @interface
 *  @typedef {object} BaseUnit
 * @property {number} attack
 * @property {number} defense
 * @property {number} morale
 * @property {number} hp
 */

/** @implements {BaseUnit} */
App.SecExp.BaseMilitiaUnit = class BaseMilitiaUnit {
	static get attack() {
		return 7 + App.SecExp.getAppliedUpgrades('human').attack + App.SecExp.getEdictUpgradeVal("Militia", "attack");
	}

	static get defense() {
		return 5 + App.SecExp.getAppliedUpgrades('human').defense + App.SecExp.getEdictUpgradeVal("Militia", "defense");
	}

	static get morale() {
		return 140 + App.SecExp.getAppliedUpgrades('human').morale + App.SecExp.getEdictUpgradeVal("Militia", "morale");
	}

	static get hp() {
		return 3 + App.SecExp.getAppliedUpgrades('human').hp + App.SecExp.getEdictUpgradeVal("Militia", "hp");
	}
};

/** @implements {BaseUnit} */
App.SecExp.BaseSlaveUnit = class BaseSlaveUnit {
	static get attack() {
		return 8 + App.SecExp.getAppliedUpgrades('human').attack + App.SecExp.getEdictUpgradeVal("Slave", "attack");
	}

	static get defense() {
		return 3 + App.SecExp.getAppliedUpgrades('human').defense + App.SecExp.getEdictUpgradeVal("Slave", "defense");
	}

	static get morale() {
		return 110 + App.SecExp.getAppliedUpgrades('human').morale + App.SecExp.getEdictUpgradeVal("Slave", "morale");
	}

	static get hp() {
		return 3 + App.SecExp.getAppliedUpgrades('human').hp + App.SecExp.getEdictUpgradeVal("Slave", "hp");
	}
};

/** @implements {BaseUnit} */
App.SecExp.BaseMercUnit = class BaseMercUnit {
	static get attack() {
		return 8 + App.SecExp.getAppliedUpgrades('human').attack + App.SecExp.getEdictUpgradeVal("Merc", "attack");
	}

	static get defense() {
		return 4 + App.SecExp.getAppliedUpgrades('human').defense + App.SecExp.getEdictUpgradeVal("Merc", "defense");
	}

	static get morale() {
		return 125 + App.SecExp.getAppliedUpgrades('human').morale + App.SecExp.getEdictUpgradeVal("Merc", "morale");
	}

	static get hp() {
		return 4 + App.SecExp.getAppliedUpgrades('human').hp + App.SecExp.getEdictUpgradeVal("Merc", "hp");
	}
};

/** @implements {BaseUnit} */
App.SecExp.BaseDroneUnit = class BaseDroneUnit {
	static get attack() {
		return 7 + App.SecExp.getAppliedUpgrades('drone').attack;
	}

	static get defense() {
		return 3 + App.SecExp.getAppliedUpgrades('drone').defense;
	}

	static get morale() {
		return 200;
	}

	static get hp() {
		return 3 + App.SecExp.getAppliedUpgrades('drone').hp;
	}
};

/** @implements {BaseUnit} */
App.SecExp.BaseRaiderUnit = class BaseRaiderUnit {
	static get attack() {
		return 7;
	}

	static get defense() {
		return 2;
	}

	static get morale() {
		return 100;
	}

	static get hp() {
		return 2;
	}
};

/** @implements {BaseUnit} */
App.SecExp.BaseFreeCityUnit = class BaseFreeCityUnit {
	static get attack() {
		return 6;
	}

	static get defense() {
		return 4;
	}

	static get morale() {
		return 130;
	}

	static get hp() {
		return 3;
	}
};

/** @implements {BaseUnit} */
App.SecExp.BaseOldWorldUnit = class BaseOldWorldUnit {
	static get attack() {
		return 8;
	}

	static get defense() {
		return 4;
	}

	static get morale() {
		return 110;
	}

	static get hp() {
		return 2;
	}
};

/** @implements {BaseUnit} */
App.SecExp.BaseFreedomFighterUnit = class BaseFreedomFighterUnit {
	static get attack() {
		return 9;
	}

	static get defense() {
		return 2;
	}

	static get morale() {
		return 160;
	}

	static get hp() {
		return 2;
	}
};

/** @implements {BaseUnit} */
App.SecExp.BaseSpecialForcesUnit = class BaseSpecialForcesUnit {
	static get attack() {
		return 8 + App.SecExp.getAppliedUpgrades('human').attack;
	}

	static get defense() {
		return 4 + App.SecExp.getAppliedUpgrades('human').defense;
	}

	static get morale() {
		return 140 + App.SecExp.getAppliedUpgrades('human').morale;
	}

	static get hp() {
		return 4 + App.SecExp.getAppliedUpgrades('human').hp;
	}
};

/** Unit base class */
App.SecExp.Unit = class SecExpUnit {
	/** @param {FC.SecExp.UnitData} data
	 * @param {BaseUnit} baseUnit
	 */
	constructor(data, baseUnit) {
		this._data = data;
		this._baseUnit = baseUnit;
	}

	/** @abstract
	 * @returns {number} */
	get attack() {
		throw "derive me";
	}

	/** @abstract
	 * @returns {number} */
	get defense() {
		throw "derive me";
	}

	/** @abstract
	 * @returns {number} */
	get morale() {
		return this._baseUnit.morale; // no morale modifiers
	}

	/** @abstract
	 * @returns {number} */
	get hp() {
		throw "derive me";
	}

	/** @abstract
	 * @returns {string} */
	describe() {
		throw "derive me";
	}

	/** @abstract
	 * @returns {string} */
	printStats() {
		throw "derive me";
	}
};

App.SecExp.DroneUnit = class SecExpDroneUnit extends App.SecExp.Unit {
	/** @param {FC.SecExp.PlayerUnitData} data
	 * @param {BaseUnit} baseUnit
	 */
	constructor(data, baseUnit) {
		super(data, baseUnit);
		this._data = data; // duplicate assignment, just for TypeScript
	}

	get attack() {
		const equipmentFactor = this._data.equip * App.SecExp.equipMod;
		return this._baseUnit.attack * (1 + equipmentFactor);
	}

	get defense() {
		const equipmentFactor = this._data.equip * App.SecExp.equipMod;
		return this._baseUnit.defense * (1 + equipmentFactor);
	}

	get hp() {
		return this._baseUnit.hp * this._data.troops;
	}

	describe() {
		return App.SecExp.describeUnit(this._data, "Bots");
	}

	printStats() {
		let r = [];
		r.push(`<br>Security drones base attack: ${this._baseUnit.attack} (After modifiers: ${Math.trunc(this.attack)})`);
		r.push(`<br>Security drones base defense: ${this._baseUnit.defense} (After modifiers: ${Math.trunc(this.defense)})`);
		r.push(`<br>Equipment bonus: +${this._data.equip * 15}%`);
		r.push(`<br>Security drones base hp: ${this._baseUnit.hp} (Total after modifiers for ${this._data.troops} drones: ${this.hp})`);
		r.push(`<br>Security drones base morale: ${this._baseUnit.morale}`);
		return r.join(` `);
	}
};

App.SecExp.HumanUnit = class SecExpHumanUnit extends App.SecExp.Unit {
	/** @param {FC.SecExp.PlayerHumanUnitData} data
	 * @param {BaseUnit} baseUnit
	 * @param {string} descriptionType
	 */
	constructor(data, baseUnit, descriptionType) {
		super(data, baseUnit);
		this._data = data; // duplicate assignment, just for TypeScript
		this._descType = descriptionType;
	}

	get attack() {
		const equipmentFactor = this._data.equip * App.SecExp.equipMod;
		const experienceFactor = App.SecExp.trainingValueToBonusFactor(this._data.training);
		const loyaltyFactor = App.SecExp.loyaltyValueToBonusFactor(this._data.loyalty);
		const SFFactor = 0.20 * this._data.SF;
		return this._baseUnit.attack * (1 + equipmentFactor + experienceFactor + loyaltyFactor + SFFactor) + this._data.cyber;
	}

	get defense() {
		const equipmentFactor = this._data.equip * App.SecExp.equipMod;
		const experienceFactor = App.SecExp.trainingValueToBonusFactor(this._data.training);
		const loyaltyFactor = App.SecExp.loyaltyValueToBonusFactor(this._data.loyalty);
		const SFFactor = 0.20 * this._data.SF;
		return this._baseUnit.defense * (1 + equipmentFactor + experienceFactor + loyaltyFactor + SFFactor) + this._data.cyber;
	}

	get hp() {
		const medicFactor = 0.25 * this._data.medics;
		const singleTroopHp = this._baseUnit.hp * (1 + medicFactor) + this._data.cyber;
		return singleTroopHp * this._data.troops;
	}

	describe() {
		return App.SecExp.describeUnit(this._data, this._descType);
	}

	printStats() {
		let r = [];
		r.push(`<br>${this._descType} base attack: ${this._baseUnit.attack} (After modifiers: ${Math.trunc(this.attack)})`);
		r.push(`<br>${this._descType} base defense: ${this._baseUnit.defense} (After modifiers: ${Math.trunc(this.defense)})`);
		if (this._data.equip > 0) {
			r.push(`<br>Equipment bonus: +${this._data.equip * 15}%`);
		}
		if (this._data.cyber > 0) {
			r.push(`<br>Cyber enhancements bonus: +1`);
		}
		if (this._data.training > 0) {
			r.push(`<br>Experience bonus: +${Math.trunc(App.SecExp.trainingValueToBonusFactor(this._data.training)*100)}%`);
		}
		if (this._data.loyalty > 0) {
			r.push(`<br>Loyalty bonus: +${Math.trunc(App.SecExp.loyaltyValueToBonusFactor(this._data.loyalty)*100)}%`);
		}
		if (this._data.SF > 0) {
			r.push(`<br>Special Force advisors bonus: +20%`);
		}
		r.push(`<br>${this._descType} base morale: ${this._baseUnit.morale} (After modifiers: ${this.morale})`);
		if (jsDef(V.SecExp.buildings.barracks) && V.SecExp.buildings.barracks.luxury > 0) {
			r.push(`<br>Barracks bonus: +${V.SecExp.buildings.barracks.luxury * 5}%`);
		}
		r.push(`<br>${this._descType} base hp: ${this._baseUnit.hp} (Total after modifiers for ${this._data.troops} troops: ${this.hp})`);
		if (this._data.medics > 0) {
			r.push(`<br>Medics detachment bonus: +25%`);
		}
		return r.join(` `);
	}
};

App.SecExp.troopsFromSF = function() {
	if (V.slaveRebellion !== 1 || V.citizenRebellion !== 1) { // attack: how many troops can we actually carry?
		const transportMax = Math.trunc(125 * (V.SF.Squad.GunS + (V.terrain !== "oceanic" ? ((V.SF.Squad.AV + V.SF.Squad.TV)/2) : 0)));
		return Math.min(transportMax, V.SF.ArmySize);
	} else {
		return V.SF.ArmySize; // rebellion: transport capabilities are irrelevant
	}
};

App.SecExp.SFUnit = class SFUnit extends App.SecExp.Unit {
	constructor() {
		super(null, App.SecExp.BaseSpecialForcesUnit);
		this._distancePenalty = (V.slaveRebellion !== 1 || V.citizenRebellion !== 1) ? 0.10 : 0.0;
	}

	get attack() {
		// ignores base attack? weird.
		const attackUpgrades = V.SF.Squad.Armoury + V.SF.Squad.Drugs + V.SF.Squad.AA + (V.terrain !== "oceanic" ? V.SF.Squad.AV : 0);
		return (0.75 - this._distancePenalty) * attackUpgrades;
	}

	get defense() {
		// ignores base defense? weird.
		const defenseUpgrades = V.SF.Squad.Armoury + V.SF.Squad.Drugs + (V.SF.Squad.AA + V.SF.Squad.TA) / 2 + (V.terrain !== "oceanic" ? (V.SF.Squad.AV + V.SF.Squad.TV) / 2 : 0);
		return (0.5 - this._distancePenalty) * defenseUpgrades;
	}

	get hp() {
		return this._baseUnit.hp * App.SecExp.troopsFromSF();
	}
};

App.SecExp.EnemyUnit = class SecExpEnemyUnit extends App.SecExp.Unit {
	/** @param {FC.SecExp.UnitData} data
	 * @param {BaseUnit} baseUnit
	 */
	constructor(data, baseUnit) {
		super(data, baseUnit);
	}

	get attack() {
		const equipmentFactor = this._data.equip * App.SecExp.equipMod;
		return this._baseUnit.attack * (1 + equipmentFactor) + V.SecExp.buildings.weapManu ? V.SecExp.buildings.weapManu.sellTo.oldWorld : 0;
	}

	get defense() {
		const equipmentFactor = this._data.equip * App.SecExp.equipMod;
		return this._baseUnit.defense * (1 + equipmentFactor) + V.SecExp.buildings.weapManu ? V.SecExp.buildings.weapManu.sellTo.oldWorld : 0;
	}

	get hp() {
		return this._baseUnit.hp * this._data.troops;
	}
};

App.SecExp.IrregularUnit = class SecExpEnemyUnit extends App.SecExp.Unit {
	/** @param {FC.SecExp.UnitData} data
	 * @param {BaseUnit} baseUnit
	 */
	constructor(data, baseUnit) {
		super(data, baseUnit);
	}

	get attack() {
		const equipmentFactor = this._data.equip * App.SecExp.equipMod;
		return (this._baseUnit.attack - App.SecExp.getAppliedUpgrades('human').attack) * (1 + equipmentFactor);
	}

	get defense() {
		const equipmentFactor = this._data.equip * App.SecExp.equipMod;
		return (this._baseUnit.defense - App.SecExp.getAppliedUpgrades('human').defense) * (1 + equipmentFactor);
	}

	get hp() {
		return (this._baseUnit.hp - App.SecExp.getAppliedUpgrades('human').hp) * this._data.troops;
	}
};

App.SecExp.describeUnit = (function() {
	return description;

	/**
	 * @param {FC.SecExp.PlayerUnitData} input
	 * @param {string} unitType
	 */
	function description(input, unitType = '') {
		let r = ``; const brief = V.SecExp.settings.unitDescriptions;

		if (unitType !== "Bots") {
			r += `<br><strong>${input.platoonName}</strong>${!brief ? ``:`. `} `;
			if (brief === 0) {
				if (input.battlesFought > 1) {
					r += `has participated in ${input.battlesFought} battles and is ready to face the enemy once more at your command. `;
				} else if (input.battlesFought === 1) {
					r += `is ready to face the enemy once more at your command. `;
				} else {
					r += `is ready to face the enemy in battle. `;
				}
				r += `<br>Its ${input.troops} men and women are `;

				if (unitType === "Militia") {
					r += `all proud citizens of your arcology, willing to put their lives on the line to protect their home. `;
				} else if (unitType === "Slaves") {
					r += `slaves in your possession, tasked with the protection of their owner and their arcology. `;
				} else if (unitType === "Mercs") {
					r += `mercenaries contracted to defend the arcology against external threats. `;
				}
			} else {
				r += `Battles fought: ${input.battlesFought}. `;
			}
		} else {
			if (brief === 0) {
				r += `<br>The drone unit is made up of ${input.troops} drones. All of which are assembled in an ordered formation in front of you, absolutely silent and ready to receive their orders.`;
			} else {
				r += `<br>Drone squad.`;
			}
		}

		if (brief === 0) {
			if (input.troops < input.maxTroops) {
				r += `The unit is not at its full strength of ${input.maxTroops} operatives. `;
			}
		} else {
			r += `Unit size: ${input.troops}/${input.maxTroops}.`;
		}

		if (brief === 0) {
			if (unitType !== "Bots") {
				if (input.equip === 0) {
					r += `They are issued with simple, yet effective equipment: firearms, a few explosives and standard uniforms, nothing more. `;
				} else if (input.equip === 1) {
					r += `They are issued with good, modern equipment: firearms, explosives and a few specialized weapons like sniper rifles and machine guns. They also carry simple body armor. `;
				} else if (input.equip === 2) {
					r += `They are issued with excellent, high tech equipment: modern firearms, explosives, specialized weaponry and modern body armor. They are also issued with modern instruments like night vision and portable radars. `;
				} else {
					r += `They are equipped with the best the modern world has to offer: modern firearms, explosives, specialized weaponry, experimental railguns, adaptive body armor and high tech recon equipment. `;
				}
			} else {
				if (input.equip === 0) {
					r += `They are equipped with light weaponry, mainly anti-riot nonlethal weapons. Not particularly effective in battle. `;
				} else if (input.equip === 1) {
					r += `They are equipped with light firearms, not an overwhelming amount of firepower, but with their mobility good enough to be effective. `;
				} else if (input.equip === 2) {
					r += `They are equipped with powerful, modern firearms and simple armor mounted around their frames. They do not make for a pretty sight, but on the battlefield they are a dangerous weapon. `;
				} else {
					r += `They are equipped with high energy railguns and adaptive armor. They are a formidable force on the battlefield, even for experienced soldiers. `;
				}
			}
		} else {
			r += `Equipment quality: `;
			if (input.equip === 0) {
				r += `basic. `;
			} else if (input.equip === 1) {
				r += `average. `;
			} else if (input.equip === 2) {
				r += `high. `;
			} else {
				r += `advanced. `;
			}
		}

		if (unitType !== "Bots") {
			if (brief === 0) {
				if (input.training <= 33) {
					r += `They lack the experience to be considered professionals, but `;
					if (unitType === "Militia") {
						r += `their eagerness to defend the arcology makes up for it. `;
					} else if (unitType === "Slaves") {
						r += `their eagerness to prove themselves makes up for it. `;
					} else if (unitType === "Mercs") {
						r += `they're trained more than enough to still be an effective unit. `;
					}
				} else if (input.training <= 66) {
					r += `They have trained `;
					if (input.battlesFought > 0) {
						r += `and fought `;
					}
					r += `enough to be considered disciplined, professional soldiers, ready to face the battlefield. `;
				} else {
					r += `They are consummate veterans, with a wealth of experience and perfectly trained. On the battlefield they are a well oiled war machine capable of facing pretty much anything. `;
				}

				if (input.loyalty < 10) {
					r += `The unit is extremely disloyal. Careful monitoring of their activities and relationships should be implemented. `;
				} else if (input.loyalty < 33) {
					r += `Their loyalty is low. Careful monitoring of their activities and relationships is advised. `;
				} else if (input.loyalty < 66) {
					r += `Their loyalty is not as high as it can be, but they are not actively working against their arcology owner. `;
				} else if (input.loyalty < 90) {
					r += `Their loyalty is high and strong. The likelihood of this unit betraying the arcology is low to non-existent. `;
				} else {
					r += `The unit is fanatically loyal. They would prefer death over betrayal. `;
				}

				if (input.cyber > 0) {
					r += `The soldiers of the unit have been enhanced with numerous cyberaugmentations which greatly increase their raw power. `;
				}
				if (input.medics > 0) {
					r += `The unit has a dedicated squad of medics that will follow them in battle. `;
				}
				if (V.SF.Toggle && V.SF.Active >= 1 && input.SF > 0) {
					r += `The unit has "advisors" from ${V.SF.Lower} that will help the squad remain tactically aware and active. `;
				}
			} else {
				r += `\nTraining: `;
				if (input.training <= 33) {
					r += `low. `;
				} else if(input.training <= 66) {
					r += `medium. `;
				} else {
					r += `high. `;
				}

				r += `Loyalty: `;
				if (input.loyalty < 10) {
					r += `extremely disloyal. `;
				} else if (input.loyalty < 33) {
					r += `low. `;
				} else if (input.loyalty < 66) {
					r += `medium. `;
				} else if (input.loyalty < 90) {
					r += `high. `;
				} else {
					r += `fanatical. `;
				}

				if (jsDef(input.cyber) && input.cyber > 0) {
					r += `\nCyberaugmentations applied. `;
				}
				if (jsDef(input.medics) && input.medics > 0) {
					r += `Medical squad attached. `;
				}
				if (V.SF.Toggle && V.SF.Active >= 1 && jsDef(input.SF) && input.SF > 0) {
					r += `${capFirstChar(V.SF.Lower || "the special force")} "advisors" attached. `;
				}
			}
		}

		if (!input.active) {
			r += `<br>This unit has lost too many operatives `;
			if (jsDef(input.battlesFought)) {
				r += `in the ${input.battlesFought} it fought `;
			}
			r += `and can no longer be considered a unit at all.`;
		}
		return r;
	}
})();

App.SecExp.mercenaryAvgLoyalty = function() {
	return _.mean(V.mercUnits.filter((u) => u.active === 1).map((u) => u.loyalty));
};

App.SecExp.Manpower = {
	get totalMilitia() {
		return this.employedMilitia + this.freeMilitia;
	},

	get employedMilitia() {
		return V.militiaUnits.reduce((acc, cur) => acc + cur.troops, 0);
	},

	get freeMilitia() {
		return V.militiaFreeManpower;
	},

	get employedSlave() {
		return V.slaveUnits.reduce((acc, cur) => acc + cur.troops, 0);
	},

	get totalMerc() {
		return this.employedMerc + this.freeMerc;
	},

	get employedMerc() {
		return V.mercUnits.reduce((acc, cur) => acc + cur.troops, 0);
	},

	get freeMerc() {
		return V.mercFreeManpower;
	},

	get employedOverall() {
		return this.employedMerc + this.employedMilitia + this.employedSlave;
	}
};