code:
:: edicts [nobr]

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

''__Active Edicts__''

<<if $alternativeRents == 1>>

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

<<if $enslavementRights == 1>>

''Enslavement rights:'' you are the only authority able to declare a person enslaved or not.
	[[Repeal|edicts][$enslavementRights = 0, $edictsAuthUpkeep -= 10]]
<</if>>

<<if $sellData == 1>>

''Private Data marketization:'' you are selling private citizens' data to the best bidder.
	[[Repeal|edicts][$sellData = 0, $edictsAuthUpkeep -= 10]]
<</if>>

<<if $propCampaignBoost == 1>>

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

<<if $tradeLegalAid == 1>>

''Legal aid for new businesses:'' New businesses can rely on your help for legal expenses and issues.
	[[Repeal|edicts][$tradeLegalAid = 0, $edictsUpkeep -= 1000]]
<</if>>
<<if $taxTrade == 1>>

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

<<if $slaveWatch == 1>>

''@@.lime;Slave mistreatment watch:@@'' slaves are able access a special security service in case of mistreatment.
	[[Repeal|edicts][$slaveWatch = 0, $edictsUpkeep -= 1000]]
<</if>>

<<if $subsidyChurch == 1>>

''@@.lime;Religious activities subsidy:@@'' you are providing economic support to religious activities following the official dogma.
	[[Repeal|edicts][$subsidyChurch = 0, $edictsUpkeep -= 1000]]
<</if>>

<<if $SFSupportLevel > 0>>

__Special Force:__
	<<if $SFSupportLevel == 1>>

''Equipment provision:'' $securityForceName is providing the security HQ with advanced equipment, boosting its efficacy.
		[[Repeal|edicts][$SFSupportLevel--, $SFSupportUpkeep -= 1000, $reqHelots += 5]]
	<<elseif $SFSupportLevel == 2>>

''Personnel training:'' $securityForceName is currently providing advanced equipment and training to security HQ personnel.
		[[Repeal|edicts][$SFSupportLevel--, $SFSupportUpkeep -= 2000, $reqHelots += 5]]
	<<elseif $SFSupportLevel == 3>>

''Troops detachment:'' $securityForceName has currently transferred troops to the security department HQ in addition to providing advanced equipment and training to security HQ personnel.
		[[Repeal|edicts][$SFSupportLevel--, $SFSupportUpkeep -= 3000, $reqHelots += 5]]
	<<elseif $SFSupportLevel == 4>>

''Full support:''$securityForceName 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.
		[[Repeal|edicts][$SFSupportLevel--, $SFSupportUpkeep -= 3000, $reqHelots += 5]]
	<<elseif $SFSupportLevel == 5>>

''Network assistance:''$securityForceName 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.
		[[Repeal|edicts][$SFSupportLevel--, $SFSupportUpkeep -= 4000, $secHQUpkeep -= 1000, $reqHelots += 5]]
	<</if>>
<</if>>

<<if $limitImmigration == 1 || $openBorders == 1>>

__Immigration:__

	<<if $limitImmigration == 1>>

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

	<<if $openBorders == 1>>

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

__Weapons:__

<<if $weaponsLaw == 0>>

''Forbid weapons inside the arcology:'' residents are forbidden to buy, sell and keep weaponry while within the arcology.
	[[Repeal|edicts][$weaponsLaw = 3, $edictsAuthUpkeep -= 30]]
<<elseif $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][$weaponsLaw = 3, $edictsAuthUpkeep -= 10]]
<<elseif $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][$weaponsLaw = 3, $edictsAuthUpkeep -= 20]]
<<else>>

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

<<if $hasFoughtOnce == 1>>

__Defense Force:__
	<<if $soldierWages == 0>>

''Low wages for soldiers:'' wages for soldiers are set to a low level compared to market standards.
		[[Repeal|edicts][$soldierWages = 1]]
	<<elseif $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][$soldierWages = 1]]
	<</if>>

	<<if $slavesOfficers == 1>>

''Slave Officers:'' your trusted slaves are allowed to lead the defense forces of the arcology.
		[[Repeal|edicts][$slavesOfficers = 0, $edictsAuthUpkeep -= 10]]
	<</if>>

	<<if $mercenaries > 0>>
		<<if $discountMercenaries == 1>>

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

	<<if $militiaFounded == 1>>
		<<if $conscription == 1>>

''Conscription:'' every citizen is required to train in the militia and serve the arcology for a limited amount of time.
			[[Repeal|edicts][$conscription = 0, $recruitVolunteers = 1]]
		<</if>>
		<<if $militaryService == 1>>

''Obligatory military service:'' every citizen is required to register and serve under the militia.
			[[Repeal|edicts][$militaryService = 0, $recruitVolunteers = 1]]
		<</if>>
		<<if $militarizedSociety == 1>>

''Militarized Society:'' every adult citizen is required to train and actively participate in the military of the arcology.
			[[Repeal|edicts][$militarizedSociety = 0, $recruitVolunteers = 1]]
		<</if>>

		<<if $militaryExemption == 1>>

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

		<<if $lowerRquirements == 1>>

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

		<<if $noSubhumansInArmy == 1>>

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

		<<if $pregExemption == 1>>

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

	<<if $militiaSoldierPrivilege == 1>>

''Special militia privileges:'' citizens joining the militia are exempt from rent payment.
		[[Repeal|edicts][$militiaSoldierPrivilege = 0]]
	<</if>>

	<<if $slaveSoldierPrivilege == 1>>

''Special slaves privileges:'' Slaves into the army are allowed to have material possessions.
		[[Repeal|edicts][$slaveSoldierPrivilege = 0, $edictsAuthUpkeep -= 10]]
	<</if>>

	<<if $mercSoldierPrivilege == 1>>

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

	<<if $martialSchool == 1>>

''@@.lime;Slave martial schools:@@'' specialized schools are training slaves in martial arts and bodyguarding.
		[[Repeal|edicts][$martialSchool = 0, $edictsUpkeep -= 1000, $slaveBaseMorale -= 5]]
	<</if>>

	<<if $eliteOfficers == 1>>

''@@.lime;Elite officers:@@'' officers are exclusively recruited from the elite of society.
		[[Repeal|edicts][$eliteOfficers = 0, $militiaBaseMorale += 5, $slaveBaseMorale -= 5]]
	<</if>>

	<<if $liveTargets == 1>>

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

<<if $FSAnnounced>>
	<<if $legionTradition == 1>>

''@@.lime;Legionaries traditions:@@'' you are funding specialized training for your recruits following the Roman tradition of professional armies.
		[[Repeal|edicts][$legionTradition = 0, $edictsUpkeep -= 1000, $militiaBaseDefense -= 2, $militiaBaseMorale -= 5, $militiaBaseHp--]]
	<</if>>

	<<if $pharaonTradition == 1>>

''@@.lime;Pharaonic traditions:@@'' you are funding specialized training for your recruits to turn them into an army worthy of a pharaon.
		[[Implement|edicts][$pharaonTradition = 0, $edictsUpkeep -= 1000, $militiaBaseAttack -= 2, $militiaBaseDefense -= 2, $militiaBaseMorale -= 10]]

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

	<<if $eagleWarriors == 1>>

''@@.lime;Eagle warriors traditions:@@'' you are funding specialized training for your mercenaries following the Aztec tradition of elite warriors.
		[[Repeal|edicts][$eagleWarriors = 0, $edictsUpkeep -= 1000, $mercBaseAttack -= 4, $mercBaseDefense += 2, $mercBaseMorale -= 10]]
	<</if>>

	<<if $ronin == 1>>

''@@.lime;Ronin traditions:@@'' you are funding specialized training for your mercenaries following the Japanese tradition of elite errant samurai.
		[[Repeal|edicts][$ronin = 0, $edictsUpkeep -= 1000, $mercBaseAttack -= 2, $mercBaseDefense -= 2, $mercBaseMorale -= 10]]
	<</if>>

	<<if $mamluks == 1>>

''@@.lime;Mamluks traditions:@@'' you are funding specialized training for your slaves following the Arabian tradition of mamluks slave soldiers.
		[[Repeal|edicts][$mamluks = 0, $edictsUpkeep -= 1000, $slaveBaseAttack -= 2, $slaveBaseHp--, $slaveBaseMorale -= 10]]
	<</if>>

	<<if $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][$sunTzu = 0, $edictsUpkeep -= 1000, $militiaBaseAttack--, $militiaBaseDefense--, $mercBaseAttack--, $mercBaseDefense--, $slaveBaseAttack--, $slaveBaseDefense--, $militiaBaseMorale -= 5, $mercBaseMorale -= 5, $slaveBaseMorale -= 5]]
	<</if>>
<</if>>

''__Available Edicts__''

//Passing any edict will cost <<print cashFormat(5000)>> and some authority. More edicts will become available as the arcology develops.//

<<if $alternativeRents == 0>>

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

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

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

<<if $enslavementRights == 0>>

''Enslavement rights:'' the arcology owner will be the only authority able to declare a person enslaved or not.
	<<if $authority >= 1000>>
		[[Implement|edicts][$enslavementRights = 1, $cash -=5000, $authority -= 1000, $edictsAuthUpkeep += 10]]
	<<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 $sellData == 0 && ($secUpgrades.nanoCams == 1 ||  $secUpgrades.cyberBots == 1 ||  $secUpgrades.eyeScan == 1 ||  $secUpgrades.cryptoAnalyzer == 1 ||  $crimeUpgrades.autoTrial == 1 ||  $crimeUpgrades.autoArchive == 1 ||  $crimeUpgrades.worldProfiler == 1 ||  $crimeUpgrades.advForensic == 1)>>

''Private Data marketization:'' allow the selling of private citizens' data.
	<<if $authority >= 1000>>
		[[Implement|edicts][$sellData = 1, $cash -=5000, $authority -= 1000, $edictsAuthUpkeep += 10]]
	<<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 $propHub == 1>>
	<<if $propCampaignBoost == 0>>

''Obligatory educational material:'' force residents to read curated educational material about the arcology.
		<<if $authority >= 1000>>
			[[Implement|edicts][$propCampaignBoost = 1, $cash -=5000, $authority -= 1000, $edictsUpkeep += 1000]]
		<<else>>

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

    //Will increase the effectiveness of propaganda campaigns, but will incur upkeep costs.//
	<</if>>
<</if>>

<<if $transportHub == 1>>
	<<if $tradeLegalAid == 0>>

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

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

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

''Trade tariffs:'' all goods transitioning in your arcology will have to pay a transition fee.
		<<if $authority >= 1000>>
			[[Implement|edicts][$taxTrade = 1, $cash -=5000, $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 $slaveWatch == 0>>

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

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

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

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

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

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

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

<<if $securityForceCreate == 1 && $SFSupportLevel < 5>>

__Special Force:__
	<<if $SFSupportLevel == 0 && $reqHelots > 5>>

''Equipment provision:'' $securityForceName will provide the security HQ with advanced equipment.
		<<if $authority >= 1000>>
			[[Implement|edicts][$SFSupportLevel++, $cash -=5000, $authority -= 1000, $SFSupportUpkeep += 1000, $reqHelots -= 5]]
		<<else>>

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

    //Will lower the amount of personnel necessary to man the security HQ by 5, but will incur upkeep costs.//
	<<elseif $SFSupportLevel == 1 && $securityForceArcologyUpgrades != 4 && $reqHelots > 5>>

''Personnel training:'' $securityForceName will provide the security HQ personnel with advanced training.
		<<if $authority >= 1000>>
			[[Implement|edicts][$SFSupportLevel++, $cash -=5000, $authority -= 1000, $SFSupportUpkeep += 2000, $reqHelots -= 5]]
		<<else>>

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

    //Will lower the amount of personnel necessary to man the security HQ by a further 5, but will incur additional upkeep costs.//
	<<elseif $SFSupportLevel == 2 && $securityForceArcologyUpgrades != 6 && $reqHelots > 5>>

''Troops detachment:'' $securityForceName will provide troops to the security department.
		<<if $authority >= 1000>>
			[[Implement|edicts][$SFSupportLevel++, $cash -=5000, $authority -= 1000, $SFSupportUpkeep += 3000, $reqHelots -= 5]]
		<<else>>

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

    //Will lower the amount of personnel necessary to man the security HQ by a further 5, but will incur additional upkeep costs.//
	<<elseif $SFSupportLevel == 3 && $securityForceArcologyUpgrades != 6 && $reqHelots > 5>>

''Full Support:'' $securityForceName will give the security department its full support.
		<<if $authority >= 1000>>
			[[Implement|edicts][$SFSupportLevel++, $cash -=5000, $authority -= 1000, $SFSupportUpkeep += 3000, $reqHelots -= 5]]
		<<else>>

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

    //Will lower the amount of personnel necessary to man the security HQ by a further 5, but will incur additional upkeep costs.//
	<<elseif $SFSupportLevel == 4 && $securityForceArcologyUpgrades == 13 && $reqHelots > 5>>

''Network assistance:'' $securityForceName will assist the security department with installing a local version of their custom network.
		<<if $authority >= 1000>>
			[[Implement|edicts][$SFSupportLevel++, $cash -=50000, $authority -= 1000, $SFSupportUpkeep += 4000, $secHQUpkeep += 1000, $reqHelots -= 5]]
		<<else>>

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

    //Will lower the amount of personnel necessary to man the security HQ by a further 5, but will incur additional upkeep costs.//
	<</if>>
<</if>>

__Immigration:__

<<if $limitImmigration == 0>>

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

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

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

<<if $openBorders == 0>>

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

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

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

__Weapons:__
<<if $weaponsLaw == 3>>

''Heavy weaponry forbidden:'' set the range of weapons allowed within the arcology to non-heavy, non-explosive.
	<<if $authority >= 1000>>
		[[Implement|edicts][$weaponsLaw = 2, $cash -=5000, $authority -= 1000, $edictsAuthUpkeep += 10]]
	<<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 $weaponsLaw == 2>>

''All weapons allowed:'' allow residents of the arcology to buy, sell and keep weaponry of any kind within the arcology.
	<<if $authority >= 1000>>
		[[Implement|edicts][$weaponsLaw = 3, $cash -=5000, $authority -= 1000, $edictsAuthUpkeep -= 10]]
	<<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 $authority >= 1000>>
		[[Implement|edicts][$weaponsLaw = 1, $cash -=5000, $authority -= 1000, $edictsAuthUpkeep += 10]]
	<<else>>

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

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

''Heavy weaponry forbidden:'' set the range of weapons allowed within the arcology to non-heavy, non-explosive.
	<<if $authority >= 1000>>
		[[Implement|edicts][$weaponsLaw = 2, $cash -=5000, $authority -= 1000, $edictsAuthUpkeep -= 10]]
	<<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 $authority >= 1000>>
		[[Implement|edicts][$weaponsLaw = 0, $cash -=5000, $authority -= 1000, $edictsAuthUpkeep += 10]]
	<<else>>

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

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

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

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

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

<<if $hasFoughtOnce == 1 || $mercenaries > 0>>

__Defense Force__:

	<<if $soldierWages == 0>>

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

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

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

''Low wages for soldiers:'' will set the wages paid to the soldiers of the arcology to a low amount.
		<<if $authority >= 1000>>
			[[Implement|edicts][$soldierWages -= 1, $cash -=5000, $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 $authority >= 1000>>
			[[Implement|edicts][$soldierWages += 1, $cash -=5000, $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 $authority >= 1000>>
			[[Implement|edicts][$soldierWages -= 1, $cash -=5000, $authority -= 1000]]
		<<else>>

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

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

	<<if $slavesOfficers == 0>>

''Slave Officers:'' allow your trusted slaves to lead the defense forces of the arcology.
		<<if $authority >= 1000>>
			[[Implement|edicts][$slavesOfficers = 1, $cash -=5000, $authority -= 1000, $edictsAuthUpkeep += 10]]
		<<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 $discountMercenaries == 0>>

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

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

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

	<<if $militiaFounded == 0>>

''Found the militia:'' lay the groundwork for the formation of the arcology's citizens' army.
		<<if $authority >= 1000>>
			[[Implement|edicts][$militiaFounded = 1, $recruitVolunteers = 1, $cash -=5000, $authority -= 1000]]
		<<else>>

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

    //Will allow for the recruitment and training of citizens.//
	<</if>>

	<<if $militiaFounded == 1>>
		<<if $recruitVolunteers == 0>>

''Volunteers' militia:'' only volunteers will be accepted in the militia.
			<<if $authority >= 1000>>
				[[Implement|edicts][$militarizedSociety = 0, $militaryService = 0, $conscription = 0, $recruitVolunteers = 1, $cash -=5000, $authority -= 1000]]
			<<else>>

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

    //Will replenish militia manpower slowly and will cap at 2% of the total citizens population.//
		<</if>>
		<<if $conscription == 0>>

''Conscription:'' every citizen is required to train in the militia and serve the arcology if the need arises.
			<<if $authority >= 4000>>
				[[Implement|edicts][$militarizedSociety = 0, $militaryService = 0, $conscription = 1, $recruitVolunteers = 0, $cash -=5000, $authority -= 4000]]
			<<else>>

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

    //Will replenish militia manpower moderately fast and will cap at 5% of the total citizens population, but has a high authority cost//
		<</if>>
		<<if $militaryService == 0>>

''Obligatory military service:'' every citizen is required to register and serve under the militia.
			<<if $authority >= 6000>>
				[[Implement|edicts][$militarizedSociety = 0, $militaryService = 1, $conscription = 0, $recruitVolunteers = 0, $cash -=5000, $authority -= 6000]]
			<<else>>

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

    //Will quickly replenish militia manpower and will cap at 10% of the total citizens population, but has a very high authority cost//
		<</if>>
		<<if $militarizedSociety == 0>>

''Militarized Society:'' every adult citizen is required to train and participate in the defense of the arcology.
			<<if $authority >= 8000>>
				[[Implement|edicts][$militarizedSociety = 1, $militaryService = 0, $conscription = 0, $recruitVolunteers = 0, $cash -=5000, $authority -= 8000]]
			<<else>>

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

    //Will very quickly replenish militia manpower and will cap at 20% of the total citizens population, but has an extremely high authority cost//
		<</if>>

		<<if $militaryExemption == 0 && ($conscription == 1 || $militaryService == 1 || $militarizedSociety == 1)>>

''Military exemption:'' allow citizens to avoid military duty by paying a weekly fee.
			<<if $authority >= 1000>>
				[[Implement|edicts][$militaryExemption = 1, $cash -=5000, $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 $arcologies[0].FSHedonisticDecadence >= 40>>
		<<if $lowerRquirements == 0>>

''@@.lime;Revised minimum requirements:@@'' will allow citizens outside the normally accepted range to join the militia.
			<<if $authority >= 1000>>
				[[Implement|edicts][$lowerRquirements = 1, $cash -=5000, $authority -= 1000, $militiaBaseDefense--, $militiaBaseHp--]]
			<<else>>

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

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

		<<if $arcologies[0].FSSubjugationist >= 40>>
		<<if $noSubhumansInArmy == 0>>

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

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

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

		<<if $arcologies[0].FSRepopulationFocus >= 40 && ($conscription == 1 || $militaryService == 1 || $militarizedSociety == 1)>>
		<<if $pregExemption == 0>>

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

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

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

	<<if $militiaSoldierPrivilege == 0 && $militiaFounded == 1>>

''Special militia privileges'' will allow citizens joining the militia to avoid paying rent.
		<<if $authority >= 1000>>
			[[Implement|edicts][$militiaSoldierPrivilege = 1, $cash -=5000, $authority -= 1000]]
		<<else>>

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

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

	<<if $slaveSoldierPrivilege == 0>>

''Special slaves privileges'' will allow slaves drafted into the army to be able to have material possessions.
		<<if $authority >= 1000>>
			[[Implement|edicts][$slaveSoldierPrivilege = 1, $cash -=5000, $authority -= 1000, $edictsAuthUpkeep += 10]]
		<<else>>

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

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

	<<if $mercSoldierPrivilege == 0 && $mercenaries > 0>>

''Special mercenary privileges'' will allow mercenaries under contract to claim part of the loot gained from battles.
		<<if $authority >= 1000>>
			[[Implement|edicts][$mercSoldierPrivilege = 1, $cash -=5000, $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 $arcologies[0].FSPhysicalIdealist >= 40>>
		<<if $martialSchool == 0>>

''@@.lime;Slave martial schools:@@'' specialized schools will be set up to train slaves in martial arts and bodyguarding.
			<<if $authority >= 1000>>
				[[Implement|edicts][$martialSchool = 1, $cash -=5000, $authority -= 1000, $edictsUpkeep += 1000, $slaveBaseMorale += 5]]
			<<else>>

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

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

	<<if $arcologies[0].FSRestart >= 40>>
		<<if $eliteOfficers == 0>>

''@@.lime;Elite officers:@@'' officers will be exclusively recruited from the elite of society.
			<<if $authority >= 1000>>
				[[Implement|edicts][$eliteOfficers = 1, $cash -=5000, $authority -= 1000, $militiaBaseMorale += 5, $slaveBaseMorale -= 5]]
			<<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 $arcologies[0].FSDegradationist >= 40>>
		<<if $liveTargets == 0>>

''@@.lime;Live targets drills:@@'' disobedient slaves will be used as live targets at shooting ranges.
			<<if $authority >= 1000>>
				[[Implement|edicts][$liveTargets = 1, $cash -=5000, $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>>

<<if $FSAnnounced>>

__Future Societies:__
	<<if $arcologies[0].FSRomanRevivalist >= 40 && $militiaFounded == 1>>
		<<if $legionTradition == 0>>

''@@.lime;Legionaries traditions:@@'' Fund specialized training for your recruits to turn them into the professional of Roman tradition.
			<<if $authority >= 1000>>
				[[Implement|edicts][$legionTradition = 1, $cash -=5000, $authority -= 1000, $edictsUpkeep += 1000, $militiaBaseDefense += 2, $militiaBaseMorale += 5, $militiaBaseHp++]]
			<<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 && $militiaFounded == 1>>
		<<if $pharaonTradition == 0>>

''@@.lime;Pharaonic traditions:@@'' Fund specialized training for your recruits to turn them into an army worthy of a pharaon.
			<<if $authority >= 1000>>
				[[Implement|edicts][$pharaonTradition = 1, $cash -=5000, $authority -= 1000, $edictsUpkeep += 1000, $militiaBaseAttack += 2, $militiaBaseDefense += 2, $militiaBaseMorale += 10]]
			<<else>>

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

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

	<<if $arcologies[0].FSAztecRevivalist >= 40 && $mercenaries > 0>>
		<<if $eagleWarriors == 0>>

''@@.lime;Eagle warriors traditions:@@'' Fund specialized training for your mercenaries to turn them into the elite units of Aztec tradition.
			<<if $authority >= 1000>>
				[[Implement|edicts][$eagleWarriors = 1, $cash -=5000, $authority -= 1000, $edictsUpkeep += 1000, $mercBaseAttack += 4, $mercBaseDefense -= 2, $mercBaseMorale += 10]]
			<<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 && $mercenaries > 0>>
		<<if $ronin == 0>>

''@@.lime;Ronin traditions:@@'' Fund specialized training for your mercenaries to turn them into the errant samurai of Japanese tradition.
			<<if $authority >= 1000>>
				[[Implement|edicts][$ronin = 1, $cash -=5000, $authority -= 1000, $edictsUpkeep += 1000, $mercBaseAttack += 2, $mercBaseDefense += 2, $mercBaseMorale += 10]]
			<<else>>

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

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

	<<if $arcologies[0].FSArabianRevivalist >= 40>>
		<<if $mamluks == 0>>

''@@.lime;Mamluks traditions:@@'' Fund specialized training for your slaves to turn them into the mamluks slave soldiers of Arabian tradition.
			<<if $authority >= 1000>>
				[[Implement|edicts][$mamluks = 1, $cash -=5000, $authority -= 1000, $edictsUpkeep += 1000, $slaveBaseAttack += 2, $slaveBaseHp++, $slaveBaseMorale += 10]]
			<<else>>

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

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

	<<if $arcologies[0].FSChineseRevivalist >= 40>>
		<<if $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 $authority >= 1000>>
				[[Implement|edicts][$sunTzu = 1, $cash -=5000, $authority -= 1000, $militiaBaseAttack++, $militiaBaseDefense++, $mercBaseAttack++, $mercBaseDefense++, $slaveBaseAttack++, $slaveBaseDefense++, $militiaBaseMorale += 5, $mercBaseMorale += 5, $slaveBaseMorale += 5, $edictsUpkeep += 1000]]
			<<else>>

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

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


code:
:: encyclopediaSecExpBattles [nobr]
	Battles in the Security Expansion Mod

	With the Security Expansion mod enabled there is a small chance each week that an attacking force will be approaching the arcology. Their motives may vary, but their intentions are clear: hit you where it hurts.
	You arcology will start being the subject of incursions only when the [["security drones"|Encyclopedia][$encyclopedia = "Security Drones"]] upgrade has been installed.

Unit types:

Slave Units: recruitable from your stockpile of menial slaves. They are cheap, easy to replace troops that will hold the line well enough.
		Of the three they have the lowest base stats, but they have the advantage of being available from the beginning, have the lowest upkeep and can be replenished in any moment, provided enough cash is available.

Militia Units: recruitable only after a special edict is passed. Once the militia is announced recruitment laws will become available and recruits will present themselves to the barracks, waiting to be assigned to a unit.
		Militia units are slightly stronger than slave units, but their manpower is limited by the laws enacted and the citizen population.

Mercenary Units: installing a permanent platoon in the arcology is a great defensive tool, but if you need muscle outside the walls of your dominion you'll need to hire more.
		Mercenary units have the highest base stats (in almost all categories), but are also only available if the arcology is garrisoned by the mercenary platoon, are fairly slow to replenish and have the highest upkeep.
		Once garrisoned by the mercenary platoon, more mercenaries will slowly make their way to the arcology. You have little control over their number other than increasing your arcology prosperity or your reputation.

The Security Drones: The security drones are a special unit. You cannot field more than one unit of this type and their stats (with the exception of their very high morale) are fairly low, however they cheap to replenish and have a low maintenance cost. They do not accumulate experience and are not affected by morale modifiers (for better or worse).

Units statistics:

Troops: The number of active combatants the unit can field. If it reaches zero the unit will cease to be considered active. It may be reformed as a new unit without losing the upgrades given to it, but experience is lost.

Maximum Troops: The maximum number of combatants the unit can field. You can increase this number through upgrade.

Equipment: The quality of equipment given to the unit. Each level of equipment will increase attack and defense values of the unit by 15%.

Experience: The quality of training provide/acquired in battle by the unit. Experience is a 0-100 scale with increasingly high bonuses to attack, defense and morale of the unit, to a maximum of 50% at 100 experience.

Medical support: Attaching medical support to the unit will decrease the amount of casualties the unit takes in battle.

Battles:

Battles are fought automatically, but you can control various fundamental parameters, here are the most important statistics:

Readiness: readiness represents how prepared the arcology is to face an attack. For every point of readiness you can field two units. You can find upgrades for in in the security HQ.

Tactics: Tactics are the chosen plan of action. You should carefully choose one depending on the terrain, type of enemy and leader choice, because if applied successfully they can sway a battle in your favor or doom your troops.

Terrain: Terrain has a great influence on everything, but mainly on the effectiveness of the tactic chosen.

Leader: The leader is who will command the combined troops in the field. Each type of leader has its bonuses and maluses.

Leaders:

The Assistant: The assistant can lead the troops. Her performance will entirely depend on the computational power she has available. Non human soldiers will be happy to be lead by a computer however and will fight with less ardor, unless your own reputation or authority is high enough.

The Arcology Owner: You can join the fray yourself. Your performance will depend greatly on your warfare skill and your past. The troops will react to your presence depending on your social standing and your past as well.
			Do note however there is the possibility of getting wounded, which makes you unable to focus on any task for a few weeks.

Your Bodyguard: Your bodyguard can guide the troops. Her performance will greatly depend on her intelligence and past. Slaves will be happy to be lead by one of them, but militia and mercenaries will not, unless your own authority is high enough to make up for the fact they are being lead by a slave.

Your Head Girl: Your Head Girl can guide the troops. She acts very similarly to the bodyguard in battle. Be aware that both she and the bodyguard run the risk of getting wounded, potentially with grave wounds like blindness or limb loss.

An Outstanding Citizen: One of your citizens can take the leading role. Their performance will be average; however the militia will be pleased to be guided by one of them.

To allow slaves to lead troops a specific edict will have to be enacted.

A Mercenary Officer: One of the mercenary commanders can take the lead. Their performance will be above average and mercenary units will be more confident, knowing they're being lead by someone with experience.

The Colonel: The special force's colonel can take the lead. Her performance will be above average and mercenary (in addition to hers obviously) units will be more confident, knowing they're being lead by someone with experience. Her tactics have a higher chance of success along with better offence and defense.

repo_name: lemongrab/fc


code:
:: encyclopediaSecExpMain [nobr]

	The Security Expansion Mod

	''Note: The Security Expansion mod is an optional mod. It can be switched freely on and off from the game option menu or at the start of the game.''

The world of Free Cities is not a forgiving one, those who do not seek to dominate it, will inevitably be dominated themselves.
	Good rulers need to keep control of its realm, if they want to have long and prosperous lives.
	You will have to manage your @@.darkviolet;authority@@ inside the walls of your arcology, you will have to keep it @@.deepskyblue;secure@@ and keep in check @@.orangered;crime@@ and rivals alike, you will have to take up arms and command your troops against those who defy your rule.

Statistics:
		@@.darkviolet;
Authority:@@

      Representing the power the player holds over the arcology. If @@.green;[[reputation|Encyclopedia][$encyclopedia = "Arcologies and Reputation"]]@@ is how well the protagonist is known, @@.darkviolet;authority@@ is how much is feared or respected.
		Authority influences many things, but it is mainly used to enact edicts, who, similarly to policies, allow to shape the sociopolitical profile of your arcology. Like @@.green;reputation@@, @@.darkviolet;authority@@ has a maximum of <<print commaNum(20000)>>.

		@@.deepskyblue;

Security:@@

      Representing how safe the arcology is, how likely it is for a citizen to get stabbed, killed or simply mugged in the streets as well as wider concerns like
		dangerous political organizations, terrorist groups and more. It influences many things, but its main task is to combat @@.orangered;crime@@.

		@@.orangered;

Crime:@@

      Representing the accumulated power of criminals in the arcology. Rather than representing low level criminal activity, better represented by @@.deepskyblue;security@@ (or better lack of), but
		the influence, organization and radication of criminal organizations, be it classic mafia families or high tech hacker groups. Do not let their power run rampant or you'll find your treasury emptier and emptier.
		Both @@.deepskyblue;security@@ and @@.orangered;crime@@ are displayed a 0-100% scale.

The battles:

      Arcologies are sturdy structures, difficult to assault without preparation or overwhelming numbers. [["Security drones"|Encyclopedia][$encyclopedia = "Security Drones"]] can easily handle small incursion and a few well placed mercenary squads can handle the rest.
		However, in order for free cities to survive they need many things, many of which expensive. If you want your arcology to survive the tide of times, you'll better prepare your soldiers and defend the vital lifelines that connect your arcology with the rest of the world.
		For a detailed outlook of how battles work see the relative page.

Buildings:

      The Barracks: This is where troops can be prepared and organized to respond to threats encroaching on the arcology's territory.

      The Security HQ: This is where your security department will manage the @@.deepskyblue;security@@ of the arcology.

      The Propaganda Hub: This is where your propaganda department will expand and deepen your @@.darkviolet;authority@@ over the arcology.

      The TransportHub: This is where trade happens. Mainly intended as a counter to prosperity loss events.

      The RiotControlCenter: Fairly self explanatory, will help you manage rebellions.


code:
:: proclamations [nobr]

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

You can dedicate the week to issue a proclamation, a powerful tool that will have an immediate noticeable effect on the arcology.
You will use <<print $proclamationCurrency>> to enact it<<if $proclamationType != "none">> and will be about $proclamationType.<<else>>.<</if>>

<<if $authority >= 2000>>
	<<link "Use authority">>
		<<set $proclamationCurrency = "authority">>
		<<goto "proclamations">>
	<</link>>
<<else>>
	//Requires at least 2000 authority//
<</if>>
|
<<if $rep >= 4000>>
	<<link "Use reputation">>
		<<set $proclamationCurrency = "reputation">>
		<<goto "proclamations">>
	<</link>>
<<else>>
	//Requires at least 4000 reputation//
<</if>>
|
<<if $cash >= 8000>>
	<<link "Use cash">>
		<<set $proclamationCurrency = "cash">>
		<<goto "proclamations">>
	<</link>>
<<else>>
	//Requires at least <<print cashFormat(8000)>> in cash//
<</if>>

<<link "Issue a proclamation about security">>
	<<set $personalAttention = "proclamation", $proclamationType = "security">>
	<<goto "Main">>
<</link>>

//You will use your <<if $proclamationCurrency == "authority">>control over the arcology<<elseif $proclamationCurrency == "reputation">>great influence<<elseif $proclamationCurrency == "cash">> vast financial means<</if>>
to force citizens to give up on sensitive information for the good of the arcology.//

<<link "Issue a proclamation about crime">>
	<<set $personalAttention = "proclamation", $proclamationType = "crime">>
	<<goto "Main">>
<</link>>

//You will use your <<if $proclamationCurrency == "authority">>control over the arcology<<elseif $proclamationCurrency == "reputation">>great influence<<elseif $proclamationCurrency == "cash">> vast financial means<</if>>
to force the arrest of suspected citizens without passing through the normal legal procedures.//


code:
:: propagandaHub [nobr]

<<set $HackingSkillMultiplier = HSM()>>
<<if $career == "capitalist" || $career == "celebrity" || $career == "wealth">>
	<<set _HistoryDiscount = .5>>
<<else>>
	<<set _HistoryDiscount = 1>>
<</if>>

<<set $nextButton = "Back to Arcology Management", $nextLink = "Manage Arcology", $returnTo = "Manage Arcology">>

Propaganda Hub

The propaganda hub is a surprisingly inconspicuous building, dimly lit from the outside. You are well aware however of its role and its importance. You confidently enter its unassuming doorway and calmly review the work being done here.

/* classic propaganda */
<<if $propCampaign == 0>>
	<<link "Set up a propaganda campaign">>
		<<set $propCampaign += 1>>
		<<set $cash -= 5000*$upgradeMultiplierArcology*_HistoryDiscount>>
		<<set $propFocus = "social engineering">>
		<<set $propHubUpkeep += $upgradeUpkeep>>
		<<goto "propagandaHub">>
	<</link>>

Set up a propaganda campaign to align your citizens with your goals.

//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology*_HistoryDiscount))>>. Will provide the focused resource each week, but will cost reputation in upkeep.//
<<else>>
	You have set up a team of trained slaves and expert propagandists, ready to spread the message of your choosing to the population.

	<<if $propFocus == "social engineering">>
		Focus on social engineering
	<<else>>
		<<link "Focus on social engineering">>
			<<set $propFocus = "social engineering">>
			<<goto "propagandaHub">>
		<</link>>
	<</if>>
	|
	<<if $propFocus == "immigration">>
		Focus on immigration
	<<else>>
		<<link "Focus on immigration">>
			<<set $propFocus = "immigration">>
			<<goto "propagandaHub">>
		<</link>>
	<</if>>
	|
	<<if $propFocus == "enslavement">>
		Focus on enslavement
	<<else>>
		<<link "Focus on enslavement">>
			<<set $propFocus = "enslavement">>
			<<goto "propagandaHub">>
		<</link>>
	<</if>>
	|
	<<if $propFocus == "recruitment">>
		Focus on recruitment
	<<else>>
		<<link "Focus on recruitment">>
			<<set $propFocus = "recruitment">>
			<<goto "propagandaHub">>
		<</link>>
	<</if>>

	<<if $propFocus == "social engineering">>
		You are concentrating your propaganda efforts towards increasing the acceptance of your chosen future societies.
	<<elseif $propFocus == "immigration">>
		You are concentrating your propaganda efforts towards convincing more people to immigrate to your arcology.
	<<elseif $propFocus == "enslavement">>
		You are concentrating your propaganda efforts towards convincing more people to voluntarily enslave themselves.
	<<elseif $propFocus == "recruitment">>
		You are concentrating your propaganda efforts towards convincing more citizens to enter the militia.
	<</if>>

	<<if $propCampaign < 5>>
		<<link "Invest more resources in the propaganda machine">>
			<<set $propCampaign += 1>>
			<<set $cash -= 5000 * $upgradeMultiplierArcology * ($propCampaign + 1) * _HistoryDiscount*$HackingSkillMultiplier>>
			<<set $PC.hacking += .5>>
			<<set $propHubUpkeep += $upgradeUpkeep>>
			<<goto "propagandaHub">>
		<</link>>

Invest more resources into the project to increase its effectiveness.

//Costs <<print cashFormat(Math.trunc(5000 * $upgradeMultiplierArcology * ($propCampaign + 1) * _HistoryDiscount*$HackingSkillMultiplier))>>. Will provide more of the focused resource each week but increase reputation upkeep.//
	<<else>>
		You upgraded your propaganda machine to its limits.
	<</if>>
<</if>>

/* ministry of truth */
<<if $miniTruth == 0>>
	<<link "Set up the authenticity department">>
		<<set $miniTruth += 1>>
		<<set $cash -= 5000*$upgradeMultiplierArcology*_HistoryDiscount>>
		<<set $propHubUpkeep += $upgradeUpkeep>>
		<<goto "propagandaHub">>
	<</link>>

Set up a department tasked with guaranteeing the authenticity of all information available in the arcology. Of course if reality is against what is best for the arcology, then it should be redacted as well.

//Costs <<print cashFormat(Math.trunc(5000*$upgradeMultiplierArcology * _HistoryDiscount))>>. Will provide authority and unlock special upgrades, but will increase upkeep.//
<<else>>
	<<if $miniTruth < 5>>
		<<link "Enlarge the authenticity department">>
			<<set $miniTruth += 1>>
			<<set $cash -= 5000*$upgradeMultiplierArcology * ($miniTruth + 1) * _HistoryDiscount>>
			<<set $propHubUpkeep += $upgradeUpkeep>>
			<<goto "propagandaHub">>
		<</link>>

Invest more resources into the project to increase its effectiveness.

//Costs <<print cashFormat(Math.trunc(5000 * $upgradeMultiplierArcology * ($miniTruth + 1) * _HistoryDiscount))>>. Will provide more authority each week, but increases upkeep.//
	<<else>>
		You have upgraded the authenticity department to its maximum.
	<</if>>

	<<if $fakeNews == 0>>
		<<link "Install a news generator">>
			<<set $fakeNews = 1>>
			<<set $cash -= 10000*$upgradeMultiplierArcology*_HistoryDiscount>>
			<<set $propHubUpkeep += $upgradeUpkeep>>
			<<goto "propagandaHub">>
		<</link>>

Install an automatic news generator, able to fabricate thousands of plausible sounding news every day.

//Costs <<print cashFormat(Math.trunc(10000 * $upgradeMultiplierArcology * _HistoryDiscount))>>. The authenticity dept. now provides a small amount of reputation as well as authority, but increases upkeep.//
	<<else>>
		You have installed an automatic news generator. [[Remove news generator|propagandaHub][$fakeNews = 0, $propHubUpkeep -= $upgradeUpkeep]]
	<</if>>

	<<if $controlLeaks == 0>>
		<<link "Institute controlled leaks protocols">>
			<<set $controlLeaks = 1>>
			<<set $cash -= 10000*$upgradeMultiplierArcology*_HistoryDiscount*$HackingSkillMultiplier>>
			<<set $PC.hacking += 1>>
			<<set $propHubUpkeep += $upgradeUpkeep>>
			<<goto "propagandaHub">>
		<</link>>

Institute a system able to release erroneous, but plausible, information about your business, leading your competitors to prepared financial traps.

//Costs <<print cashFormat(Math.trunc(10000 * $upgradeMultiplierArcology * _HistoryDiscount*$HackingSkillMultiplier))>>. The authenticity dept. now slightly increases prosperity each week as well as authority, but increases upkeep.//
	<<else>>
		You have instituted controlled leaks protocols, able to create fabricated leaks of sensible information. [[Shut down leak protocols|propagandaHub][$controlLeaks = 0, $propHubUpkeep -= $upgradeUpkeep]]
	<</if>>
<</if>>

/* secret police */
<<if $secretService == 0>>
	<<link "Set up personal secret service">>
		<<set $secretService += 1>>
		<<set $cash -= 10000*$upgradeMultiplierArcology*_HistoryDiscount>>
		<<set $propHubUpkeep += $upgradeUpkeep>>
		<<goto "propagandaHub">>
	<</link>>

Set up a department tasked with the protection of your person, as well as operations requiring a delicate approach.

//Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology * _HistoryDiscount))>>. Will provide authority and unlock special upgrades, but will increase upkeep.//
<<else>>
	<<if $secretService < 5 && $rep >= ($secretService * 1000) + 5000>>
		<<link "Expand the secret service">>
			<<set $secretService += 1>>
			<<set $cash -= 5000*$upgradeMultiplierArcology * ($secretService + 1)>>
			<<set $propHubUpkeep += $upgradeUpkeep>>
			<<goto "propagandaHub">>
		<</link>>

Invest more resources into the project to increase its effectiveness.

//Costs <<print cashFormat(Math.trunc(5000 * $upgradeMultiplierArcology * ($secretService + 1) * _HistoryDiscount))>>. Will provide more authority each week, but increases upkeep.//
	<<elseif $secretService < 5>>
		You lack the reputation to further expand operations.
	<<else>>
		You have upgraded the secret service to its maximum.
	<</if>>

	<<if $blackOps == 0>>
		<<link "Create a black ops team">>
			<<set $blackOps = 1>>
			<<set $cash -= 10000*$upgradeMultiplierArcology*_HistoryDiscount>>
			<<set $propHubUpkeep += $upgradeUpkeep>>
			<<goto "propagandaHub">>
		<</link>>

Create a black ops team, ready to carry out corporate sabotage and sensitive operations to further your goals.

//Costs <<print cashFormat(Math.trunc(10000 * $upgradeMultiplierArcology * _HistoryDiscount))>>. The secret services now provides security as well as authority, but increases upkeep.//
	<<else>>
		You have created a black ops team.
	<</if>>

	<<if $marketInfiltration == 0>>
		<<link "Infiltrate the black market">>
			<<set $marketInfiltration = 1>>
			<<set $cash -= 10000*$upgradeMultiplierArcology*_HistoryDiscount>>
			<<set $propHubUpkeep += $upgradeUpkeep>>
			<<goto "propagandaHub">>
		<</link>>

Establish a presence on the black market in order to manipulate it.

//Costs <<print cashFormat(Math.trunc(10000 * $upgradeMultiplierArcology * _HistoryDiscount))>>. The secret services now provides cash as well as authority each week, but will increase crime growth.//
	<<else>>
		You have infiltrated the black market and are now in partial control of it. [[Withdraw from the black market|propagandaHub][$marketInfiltration = 0, $propHubUpkeep -= $upgradeUpkeep]]
	<</if>>
<</if>>


code:
:: rebellionEvents [nobr]

<<if $slaveRebellionEventFires == 1>>
	<<if $tension <= 33>>
		<<set _event = 1>>
	<<elseif $tension <= 66>>
		<<set _event = 2>>
	<<else>>
		<<set _event = 3>>
	<</if>>
<<elseif $citizenRebellionEventFires == 1>>
	<<if $tension <= 33>>
		<<set _event = 4>>
	<<elseif $tension <= 66>>
		<<set _event = 5>>
	<<else>>
		<<set _event = 6>>
	<</if>>
<</if>>

<<switch _event>>
<<case 1>>
	/* low tension slave rebellion events */
	<<set _rand = random(0,6)>>
	<<if _rand == 0>>
		This week several slaves were found plotting the death of their master. They were quickly dealt with, but their owner's choice of punishment did little to calm tensions in the arcology.
	<<elseif _rand == 1>>
		This week a large group of slaves attempted to escape. Several were recaptured, but others were deemed too dangerous and were shot on sight. The unfortunate circumstances raised the disapproval of many citizens, either because of the waste of good slaves or the brutality with which the operation was carried. With a bit of luck, however, the incident will be soon forgotten.
	<<elseif _rand == 2>>
		This week books of unknown origin and dangerous content were found in the possession of several slaves. They were mostly sociopolitical treaties, making it clear that the intent of the ones responsible was to fan the fire of rebellion. The books were quickly collected and archived, hopefully this affair will not have lasting consequences.
	<<elseif _rand == 3>>
		This week a citizen was caught giving refuge to an escaped slave. He was not able to pay for the value of the stolen goods, so he was processed as the case required and the slave returned to their rightful master. Many questions however remain without answers.
	<<elseif _rand == 4>>
		This week a member of a well known anti-slavery group was caught trying to infiltrate the arcology. During the capture attempt shots were fired and several guards were injured, and in the end the fugitive unfortunately managed to escape. Reports indicate several slaves helped the criminal, some going as far as using themselves as shields against the bullets of the security drones.
	<<elseif _rand == 5>>
		This week a slave was caught attempting to sabotage a machine in one of the factories. She explained her action as "trying to defend herself from a dangerous machine". Reports confirmed that the apparatus is indeed quite deadly, having killed several slave since it was installed, but the expert way she handled the sabotage leaves open the possibility of a deliberate plan or even external help.
	<<else>>
		This week a slave was found dead in one of the sewer tunnels. It seems she was stabbed repeatedly with a sharp object. She was fairly famous for her capabilities as a slave trainer, her old master spent not an insignificant amount of money trying to find her once he realized she was missing. The episode might have been a simple mugging gone wrong, but her activities as a slave breaker might have played a role in her homicide.
	<</if>>
	<<set $tension += random(1,5)>>
<<case 2>>
	/* med tension slave rebellion events */
	<<set _rand = random(0,5)>>
	<<if _rand == 0>>
		This week some strange reports came in: it seems some assemblies of slaves were observed several nights in a row. The slaves were traced and their masters notified, but many suspect there may be something deeper than a few slaves congregating in the night.
	<<elseif _rand == 1>>
		This week an underground railroad was discovered. The rebels did not go down without a fight, but in the end <<if $mercenaries >= 1>>your mercenaries<<else>>your security drones<</if>> managed to destroy the old tunnels they were using to ship out slaves out of the arcology.
	<<elseif _rand == 2>>
		This week a famous citizen was assaulted and brutally murdered by his slaves. The ones responsible were apprehended and dealt with easily enough, but the mere fact something like this could have happened is concerning. Those slaves had to be aware of their certain doom.
	<<elseif _rand == 3>>
		This week a group of slavers entering the arcology was assaulted. Many reported heavy injuries, but fortunately there were no casualties. The attackers were disguised, but the security systems already identified several slaves who were likely part of the group, based on camera feeds.
	<<elseif _rand == 4>>
		This week the waterways were found infected by a virulent pathogen. The cause was later found to be a diseased slave that died while in the maintenance tunnels. It's not clear if the slave was there because of orders given to him or if he was trying to escape.
	<<else>>
		This week a sleeper cell of a famous anti slavery organization was discovered in the low levels of the arcology. The group however was aware of the coming security forces and retreated before they could be dealt with.
	<</if>>
	<<set $tension += random(5,10)>>
<<case 3>>
	/* high tension slave rebellion events */
	<<set _rand = random(0,4)>>
	<<if _rand == 0>>
		This week a group of slaves took control of one of the manufacturing plants and barricaded themselves inside. It took several days of negotiations and skirmishes to finally end this little insurrection. Many of the slaves involved will be executed in the next days.
	<<elseif _rand == 1>>
		This week a number of shops were burned to the ground by rioting slaves and sympathetic citizens. It took considerable effort for the security forces to take control of the situation. Harsh punishment is required and scheduled for the instigators.
	<<elseif _rand == 2>>
		This week a mass escape attempt was barely stopped before becoming a catastrophe. Many citizens were trampled by the desperate horde of slaves. It will take some time to restore the streets involved to working order.
	<<elseif _rand == 3>>
		This week a number of riots inflamed the arcology. Many slaves took violent actions against citizens and security personnel. The number of victims keeps getting higher as still now the last sparks of revolt are still active.
	<</if>>
	<<set $tension += random(10,15)>>
<<case 4>>
	<<set _rand = random(0,6)>>
	<<if _rand == 0>>
		This week a citizen refused to pay rent, claiming ideological opposition to the arcology's owner policies. He was quickly dealt with, but his words might not have fallen silent yet.
	<<elseif _rand == 1>>
		This week books of unknown origin and dangerous content were found in the possession of several citizens. They were mostly sociopolitical treaties, making it clear that the intent of the ones responsible was to fan the fire of rebellion. Most of them were bought and archived, but a few are still circling between the citizens of the arcology.
	<<elseif _rand == 2>>
		This week a citizen was caught giving refuge to other citizens, who would be liable to be enslaved because of their debts. The situation was quickly resolved, but the misplaced generosity of that citizen might have inflamed a few souls.
	<<elseif _rand == 3>>
		This week a citizen died in one of the factories. His death sparked some outrage, even some talk of protests against the owners of the factory, but things seem to have calmed down for now.
	<<elseif _rand == 4>>
		This week a citizen refused to be evicted from his house. After some negotiations the man was forcibly removed from the property by your security forces. Unfortunately the forced entry caused some damage to the building.
	<<elseif _rand == 5>>
		This week a citizen refused to be enslaved as his contract established. With an impressive display of his rhetoric capabilities he managed to gather a small crowd agreeing with his position. The impromptu assembly was promptly disrupted by the drones.
	<<else>>
		This week a security drone was found disabled and stripped of important electronic components. It seems the act was not dictated by greed, as the most precious parts of the drone were left on the machine, but rather to cover up something that the drone saw.
	<</if>>
	<<set $tension += random(1,5)>>
<<case 5>>
	<<set _rand = random(0,5)>>
	<<if _rand == 0>>
		This week a factory was subject to a strike by a group of citizens protesting against the owner. They were promptly arrested and the factory returned to its rightful proprietor by your security department.
	<<elseif _rand == 1>>
		This week a group of citizens organized a protest against the systemic enslavement of the citizens of the arcology. Their little parade gathered a surprisingly large crowd, but it was nonetheless quickly suppressed by your forces.
	<<elseif _rand == 2>>
		This week the security department registered the formation of several assemblies of citizens, whose purpose seems to be political in nature. For now no further steps were taken, but it's a worrying sign of further political opposition within the arcology.
	<<elseif _rand == 3>>
		This week there was a protest against one of the wealthiest citizen of the arcology. Many criticize his near monopoly. Supporters of the citizen met the protesters on the streets and it was just thanks to the intervention of the security drones that violence was avoided.
	<<elseif _rand == 4>>
		This week several cameras were sabotaged and in many cases damaged beyond repair. A group of anonymous citizens claims to be responsible; their motivation is apparently the excessive surveillance in the arcology and their attack a response to the breach of their privacy.
	<<else>>
		This week several citizens barricaded themselves in a private brothel. It seems their intention is to protest against the use of ex-citizens in the sex trade, claiming that such a position is unfitting for them. The problem was quickly resolved with the intervention of the security department.
	<</if>>
	<<set $tension += random(5,10)>>
<<case 6>>
	<<set _rand = random(0,4)>>
	<<if _rand == 0>>
		This week the arcology was shaken by a number of strikes throughout the manufacturing levels. Many lament the predatory nature of Free Cities society, many other just want to cause damage to their perceived oppressors. It was a significant effort for the security department to stop all protests.
	<<elseif _rand == 1>>
		This week several factories were set aflame by their workers. The security department worked day and night to control the fire and apprehend the criminals behind the act. Many are known dissidents, but there are a fair few new faces within them. This is a worrying sign.
	<<elseif _rand == 2>>
		This week numerous riots exploded all over the arcology. Many citizens took to the streets to protest against the arcology owner and its supporters. The security forces slowly managed to stop the rioters, with no small amount of trouble and only through generous use of violence.
	<<elseif _rand == 3>>
		This week a massive protest of citizens and slaves gathered just outside the penthouse. The crowd was dispersed only after several hours. There were several victims from both sides and no shortage of injured.
	<</if>>
	<<set $tension += random(10,15)>>
<</switch>>

<<set $tension = Math.clamp($tension,0,100)>>


code:
:: rebellionGenerator [nobr]

<<set _slave = 0>>
<<set _citizen = 0>>
<<set _CSratio = $ACitizens / ($ASlaves + $helots)>>

Slaves security analysis:
<<if $authority <= 3000>>
	Your very low authority allows slaves to think too freely.<<set _slave += 30>>
<<elseif $authority <= 6000>>
	Your low authority allows slaves to think too freely.<<set _slave += 25>>
<<elseif $authority <= 9000>>
	Your moderate authority allows slaves to think a bit too freely.<<set _slave += 20>>
<<elseif $authority <= 12000>>
	Your good authority does not allow slaves to think too freely.<<set _slave += 15>>
<<elseif $authority <= 15000>>
	Your high authority does not allow slaves to think too freely.<<set _slave += 10>>
<<elseif $authority <= 18000>>
	Your very high authority does not allow slaves to think too freely.<<set _slave += 5>>
<<else>>
	Your absolute authority does not allow slaves to have a single free thought.<<set _slave += 1>>
<</if>>
<<if _CSratio <= 0.2>>
	There are a lot more slaves than citizens, making some doubt their masters are strong enough to stop them.<<set _slave += 30>>
<<elseif _CSratio <= 0.4>>
	There are a lot more slaves than citizens, making some doubt their masters are strong enough to stop them.<<set _slave += 25>>
<<elseif _CSratio <= 0.6>>
	There are more slaves than citizens, making some doubt their masters are strong enough to stop them.<<set _slave += 20>>
<<elseif _CSratio <= 0.8>>
	There are more slaves than citizens, making some doubt their masters are strong enough to stop them.<<set _slave += 15>>
<<elseif _CSratio <= 1>>
	There are fewer slaves than citizens, making some doubt they would be strong enough to defeat their masters.<<set _slave += 10>>
<<elseif _CSratio >= 1.2>>
	There are fewer slaves than citizens, making some doubt they would be strong enough to defeat their masters.<<set _slave -= 5>>
<<else>>
	Citizen and slave population is sufficiently balanced not to cause problems either way.<<set _slave -= 1>>
<</if>>
<<if $security <= 10>>
	The very low security of the arcology leaves free space for slaves to organize and agitate.<<set _slave += 30>>
<<elseif $security <= 30>>
	The low security of the arcology leaves free space for slaves to organize and agitate.<<set _slave += 20>>
<<elseif $security <= 60>>
	The moderate security of the arcology does not allow free space for slaves to organize and agitate.<<set _slave += 10>>
<<elseif $security >= 90>>
	The high security of the arcology does not allow free space for slaves to organize and agitate.<<set _slave -= 5>>
<<else>>
	The high security of the arcology does not allow free space for slaves to organize and agitate.<<set _slave -= 1>>
<</if>>
<<if $arcologies[0].FSDegradationist != "unset">>
	Many slaves are so disgusted by your degradationist society, that are willing to rise up against their masters to escape.<<set _slave += 30>>
<<elseif $arcologies[0].FSPaternalist != "unset">>
	Many slaves are content to live in your paternalist society.<<set _slave -= 5>>
<<else>>
	<<set _slave += 5>>
<</if>>
<<if $arcologies[0].FSRestart != "unset">>
	Many slaves are worried by your eugenics projects and some are pushed towards radicalization.<<set _slave += 30>>
<<elseif $arcologies[0].FSRepopulationFocus != "unset">>
	Many slaves are pleasantly happy of your repopulation effort, affording them the freedom to reproduce.<<set _slave -= 5>>
<<else>>
	<<set _slave += 5>>
<</if>>

Citizens security analysis:
<<if $authority <= 3000>>
	Your very low authority allows your citizens to think too freely.<<set _citizen += 30>>
<<elseif $authority <= 6000>>
	Your very low authority allows your citizens to think too freely.<<set _citizen += 25>>
<<elseif $authority <= 9000>>
	Your moderate authority allows your citizens to think a bit too freely.<<set _citizen += 20>>
<<elseif $authority <= 12000>>
	Your good authority does not allow your citizens to think too freely.<<set _citizen += 15>>
<<elseif $authority <= 15000>>
	Your high authority does not allow your citizens to think too freely.<<set _citizen += 10>>
<<elseif $authority <= 18000>>
	Your very high authority does not allow your citizens to think too freely.<<set _citizen += 5>>
<<else>>
	Your absolute authority does not allow your citizens to have a single free thought.<<set _citizen += 1>>
<</if>>
<<if $crime >= 90>>
	The very high crime level of the arcology breeds extreme discontent between your citizens.<<set _citizen += 30>>
<<elseif $crime >= 60>>
	The high crime level of the arcology breeds high discontent between your citizens.<<set _citizen += 15>>
<<elseif $crime >= 30>>
	The low crime level of the arcology leaves your citizens happy and satisfied.<<set _citizen += 5>>
<<else>>
	The very low crime level of the arcology leaves your citizens happy and satisfied.<<set _citizen -= 5>>
<</if>>
<<if $militiaFounded == 1>>
	<<if ($arcologies[0].FSRomanRevivalist == "unset" && $arcologies[0].FSAztecRevivalist == "unset" && $arcologies[0].FSEgyptianRevivalist == "unset" && $arcologies[0].FSEdoRevivalist == "unset" && $arcologies[0].FSArabianRevivalist == "unset" && $arcologies[0].FSChineseRevivalist == "unset")>>
		<<if $militarizedSociety == 1>>
			Many of your citizens are offended by your extreme militarization of the arcology's society.<<set _citizen += 20>>
		<<elseif $militaryService == 1>>
			Many of your citizens are offended by your militarization of the arcology's society.<<set _citizen += 15>>
		<<else>>
			<<set _citizen += 10>>
		<</if>>
	<<else>>
		<<if $militarizedSociety == 1>>
			Some of your citizens are offended by your extreme militarization of the arcology's society<<set _citizen += 10>>
		<<elseif $militaryService == 1>>
			Some of your citizens are offended by your militarization of the arcology's society<<set _citizen += 5>>
		<<else>>
			<<set _citizen -= 5>>
		<</if>>
	<</if>>
<</if>>
<<if $arcologies[0].FSNull != "unset">>
	Many of your more conservative citizens do not enjoy the cultural freedom you afford the residents of the arcology.<<set _citizen += either(20,30)>>
<</if>>
<<if $arcologies[0].FSRestart != "unset">>
	<<if _CSratio > 1>>
		Your citizens are not happy with the noticeable lack of slaves compared to their numbers.<<set _citizen += 20>>
	<<elseif _CSratio > 0.5>>
		Your citizens are not happy with the lack of slaves compared to their numbers.<<set _citizen += 15>>
	<<elseif _CSratio < 0.2>>
		<<set _citizen -= 5>>
	<</if>>
<<elseif $arcologies[0].FSRepopulationFocus != "unset">>
	<<if _CSratio < 0.5>>
		Your citizens are not happy about being outbred by the slaves of the arcology.<<set _citizen += 20>>
	<<elseif _CSratio < 1>>
		Your citizens are not happy about being outbred by the slaves of the arcology.<<set _citizen += 15>>
	<<elseif _CSratio > 1.4>>
		<<set _citizen += 5>>
	<</if>>
<</if>>

/* rolls to see if event happens */
<<if _slave < 0>>
	<<set _slave = 0>>
<<elseif _slave >= 95>>
	<<set _slave = 95>> 																	/* there's always a min 5% chance nothing happens */
<</if>>
<<if _citizen < 0>>
	<<set _citizen = 0>>
<<elseif _citizen >= 95>>
	<<set _citizen = 95>>
<</if>>
<<set _roll = random(1,_slave + _citizen)>>
<<if $brainImplant == 106>>
	<<set _slave = Math.trunc(_slave * 0.5 * $rebellionSpeed), _citizen = Math.trunc(_citizen * 0.5 * $rebellionSpeed)>>
<<else>>
	<<set _slave = Math.trunc(_slave * $rebellionSpeed), _citizen = Math.trunc(_citizen * $rebellionSpeed)>>
<</if>>
<<if _roll <= _slave>>
	<<if random(1,100) < _slave>>
		<<set $slaveRebellionEventFires = 1>>
		<<set $citizenRebellionEventFires = 0>>
		<<if $tension != 0>>
			<<set $slaveProgress += Math.trunc(random(1,5) * ($tension / 100) * 10)>>		/* progress scales with tension */
		<<else>>
			<<set $slaveProgress += random(1,5)>>
		<</if>>
	<</if>>
<<else>>
	<<if random(1,100) < _citizen>>
		<<set $slaveRebellionEventFires = 0>>
		<<set $citizenRebellionEventFires = 1>>
		<<if $tension != 0>>
			<<set $citizenProgress += Math.trunc(random(1,5) * ($tension / 100) * 10)>>
		<<else>>
			<<set $citizenProgress += random(1,5)>>
		<</if>>
	<</if>>
<</if>>

/* if there is an advancement selects a random mini event */
<<set _oldTension = $tension>>
<<if $slaveRebellionEventFires == 1 || $citizenRebellionEventFires == 1>>

	<<include "rebellionEvents">>
<<elseif $tension > 0>>
	/* otherwise tension decays */

	Tension:
	<<if $riotUpgrades.freeMedia >= 1>>
		The guaranteed free media access you offer does wonders to lower tensions in the arcology.
		<<set $tension = Math.trunc(Math.clamp($tension - $riotUpgrades.freeMedia / 2,0,100))>>
	<</if>>
	In the absence of noteworthy events, tensions in the arcology are able to relax.
	<<set $tension = Math.trunc(Math.clamp($tension * 0.97,0,100))>>
<</if>>

<<if $tension < _oldTension>>

This week @@.green;tensions relaxed@@.
<<elseif $tension == _oldTension && $tension != 0>>

This week @@.yellow;tensions did not change@@.
<<elseif $tension > _oldTension>>

This week @@.red;tension rose@@ and
	<<if $slaveRebellionEventFires == 1>>
		@@.red;slave malcontent increased@@.
	<<elseif $citizenRebellionEventFires == 1>>
		@@.red;citizen malcontent increased@@.
	<</if>>
<<elseif !isInt($tension)>>

Error: tension is outside accepted range.
<</if>>

/* resets flags */
<<set $slaveRebellionEventFires = 0>>
<<set $citizenRebellionEventFires = 0>>

/* rolls for rebellions */
<<if $slaveProgress >= 100>>
	<<if random(1,100) <= 80>>												/* 80% of firing a rebellion once progress is at 100 */
		<<set $slaveRebellion = 1>>
		<<set $slaveProgress = 0>>
		<<set $citizenProgress *= 0.2>>
	<<else>>
		<<set $slaveProgress = 100>>
	<</if>>
<<elseif $citizenProgress >= 100>>
	<<if random(1,100) <= 80>>
		<<set $citizenRebellion = 1>>
		<<set $citizenProgress = 0>>
		<<set $slaveProgress *= 0.2>>
	<<else>>
		<<set $citizenProgress = 100>>
	<</if>>
<</if>>

<<if $forceRebellion == 1 && $foughtThisWeek == 0>>
	<<if random(1,100) <= 50>>
		<<set $slaveRebellion = 1>>
		<<set $citizenRebellion = 0>>
	<<else>>
		<<set $slaveRebellion = 0>>
		<<set $citizenRebellion = 1>>
	<</if>>
<</if>>

<<set _weekMod = 0.50>>
<<if $week <= 30>>
	<<set _weekMod = 0.75>>
<<elseif $week <= 60>>
	<<set _weekMod = 1>>
<<elseif $week <= 90>>
	<<set _weekMod = 1.25>>
<<elseif $week <= 120>>
	<<set _weekMod = 1.50>>
<<else>>
	<<set _weekMod = 1.75>>
<</if>>

/* resetting ID list */
<<unset $rebellingID>>
<<set $rebellingID = []>>
<<unset $loyalID>>
<<set $loyalID = []>>

/* if a rebellion fires determine amount of rebels and rebelling units */
<<if $slaveRebellion == 1>>
	<<set $engageRule = 0>>
	<<set $lastRebellionWeeks = 0>>
	<<set $leadingTroops = "assistant">>
	<<if $hasRebelledOnce == 0>>
		<<set $hasRebelledOnce = 1>>
	<</if>>
	/* calc how many slaves and citizens participate */
	<<set _authFactor = Math.clamp(1 - ($authority / 20000),0.4,0.6)>>
	<<set _repFactor = Math.clamp($rep / 20000,0.4,0.6)>>
	<<set _rebelPercent = 0.3 * _authFactor>>
	<<set _irregularPercent = 0.2 * _repFactor>>
	<<set $attackTroops = Math.clamp(Math.trunc($ASlaves * _rebelPercent + random(-100,100)) * _weekMod,50,$ASlaves)>>
	<<set $irregulars = Math.clamp(Math.trunc($ACitizens * _irregularPercent + random(-100,100)) * _weekMod,50,$ACitizens)>>
	/* calc if units rebel */
	<<for _i = 0; _i < $slaveUnits.length; _i++>>
		<<if $slaveUnits[_i].loyalty < 10>>
			<<if random(1,100) <= 70>>
				<<set $rebellingID.push($slaveUnits[_i].ID)>>
			<</if>>
		<<elseif $slaveUnits[_i].loyalty < 33>>
			<<if random(1,100) <= 30>>
				<<set $rebellingID.push($slaveUnits[_i].ID)>>
			<</if>>
		<<elseif $slaveUnits[_i].loyalty < 66>>
			<<if random(1,100) <= 10>>
				<<set $rebellingID.push($slaveUnits[_i].ID)>>
			<</if>>
		<</if>>
		<<if !($rebellingID.includes($slaveUnits[_i].ID))>>
			<<set $loyalID.push($slaveUnits[_i].ID)>>
		<</if>>
	<</for>>
	<<for _i = 0; _i < $militiaUnits.length; _i++>>
		<<if $militiaUnits[_i].loyalty < 10>>
			<<if random(1,100) <= 70>>
				<<set $rebellingID.push($militiaUnits[_i].ID)>>
			<</if>>
		<<elseif $militiaUnits[_i].loyalty < 33>>
			<<if random(1,100) <= 30>>
				<<set $rebellingID.push($militiaUnits[_i].ID)>>
			<</if>>
		<<elseif $militiaUnits[_i].loyalty < 66>>
			<<if random(1,100) <= 10>>
				<<set $rebellingID.push($militiaUnits[_i].ID)>>
			<</if>>
		<</if>>
		<<if !($rebellingID.includes($militiaUnits[_i].ID))>>
			<<set $loyalID.push($militiaUnits[_i].ID)>>
		<</if>>
	<</for>>
	<<for _i = 0; _i < $mercUnits.length; _i++>>
		<<if $mercUnits[_i].loyalty < 10>>
			<<if random(1,100) <= 70>>
				<<set $rebellingID.push($mercUnits[_i].ID)>>
			<</if>>
		<<elseif $mercUnits[_i].loyalty < 33>>
			<<if random(1,100) <= 30>>
				<<set $rebellingID.push($mercUnits[_i].ID)>>
			<</if>>
		<<elseif $mercUnits[_i].loyalty < 66>>
			<<if random(1,100) <= 10>>
				<<set $rebellingID.push($mercUnits[_i].ID)>>
			<</if>>
		<</if>>
		<<if !($rebellingID.includes($mercUnits[_i].ID))>>
			<<set $loyalID.push($mercUnits[_i].ID)>>
		<</if>>
	<</for>>
	<<set $attackEquip = Math.clamp($weaponsLaw + random(-2,1),0,4)>>
<<elseif $citizenRebellion == 1>>
	<<set $engageRule = 0>>
	<<set $lastRebellionWeeks = 0>>
	<<if $hasRebelledOnce == 0>>
		<<set $hasRebelledOnce = 1>>
	<</if>>
	<<set $leadingTroops = "assistant">>
	/* calc how many citizens participate */
	<<set _authFactor = Math.clamp(1 - ($authority / 20000),0.4,0.6)>>
	<<set _repFactor = Math.clamp($rep / 20000,0.4,0.6)>>
	<<set _rebelPercent = 0.3 * _authFactor>>
	<<set _irregularPercent = 0.2 * _repFactor>>
	<<set $attackTroops = Math.clamp(Math.trunc($ACitizens * _rebelPercent + random(-100,100)) * _weekMod,50,$ACitizens)>>
	<<set $irregulars = Math.clamp(Math.trunc($ACitizens * _irregularPercent + random(-100,100)) * _weekMod,50,$ACitizens)>>
	/* calc if units rebel */
	<<for _i = 0; _i < $militiaUnits.length; _i++>>
		<<if $militiaUnits[_i].loyalty < 10>>
			<<if random(1,100) <= 70>>
				<<set $rebellingID.push($militiaUnits[_i].ID)>>
			<</if>>
		<<elseif $militiaUnits[_i].loyalty < 33>>
			<<if random(1,100) <= 30>>
				<<set $rebellingID.push($militiaUnits[_i].ID)>>
			<</if>>
		<<elseif $militiaUnits[_i].loyalty < 66>>
			<<if random(1,100) <= 10>>
				<<set $rebellingID.push($militiaUnits[_i].ID)>>
			<</if>>
		<</if>>
		<<if !($rebellingID.includes($militiaUnits[_i].ID))>>
			<<set $loyalID.push($militiaUnits[_i].ID)>>
		<</if>>
	<</for>>
	<<for _i = 0; _i < $slaveUnits.length; _i++>>
		<<if $slaveUnits[_i].loyalty < 10>>
			<<if random(1,100) <= 70>>
				<<set $rebellingID.push($slaveUnits[_i].ID)>>
			<</if>>
		<<elseif $slaveUnits[_i].loyalty < 33>>
			<<if random(1,100) <= 30>>
				<<set $rebellingID.push($slaveUnits[_i].ID)>>
			<</if>>
		<<elseif $slaveUnits[_i].loyalty < 66>>
			<<if random(1,100) <= 10>>
				<<set $rebellingID.push($slaveUnits[_i].ID)>>
			<</if>>
		<</if>>
		<<if !($rebellingID.includes($slaveUnits[_i].ID))>>
			<<set $loyalID.push($slaveUnits[_i].ID)>>
		<</if>>
	<</for>>
	<<for _i = 0; _i < $mercUnits.length; _i++>>
		<<if $mercUnits[_i].loyalty < 10>>
			<<if random(1,100) <= 70>>
				<<set $rebellingID.push($mercUnits[_i].ID)>>
			<</if>>
		<<elseif $mercUnits[_i].loyalty < 33>>
			<<if random(1,100) <= 30>>
				<<set $rebellingID.push($mercUnits[_i].ID)>>
			<</if>>
		<<elseif $mercUnits[_i].loyalty < 66>>
			<<if random(1,100) <= 10>>
				<<set $rebellingID.push($mercUnits[_i].ID)>>
			<</if>>
		<</if>>
		<<if !($rebellingID.includes($mercUnits[_i].ID))>>
			<<set $loyalID.push($mercUnits[_i].ID)>>
		<</if>>
	<</for>>
	<<set $attackEquip = Math.clamp($weaponsLaw + random(-1,1),0,4)>>
<<else>>
	<<set $lastRebellionWeeks++>>
<</if>>


code:
:: rebellionHandler [nobr]

<<set $nextButton = " ", $nextLink = "attackReport", $showEncyclopedia = 0>>

<<set _turn = 0>>
<<set _turns = $maxTurns * 2>>
<<set _attack = 0>>
<<set _defense = 0>>
<<set _morale = 0>>
<<set _hp = 0>>
<<set _baseHp = 0>>
<<set _enemyAttack = 0>>
<<set _enemyDefense = 0>>
<<set _enemyMorale = 0>>
<<set _enemyHp = 0>>
<<set _enemyBaseHp = 0>>
<<set _woundChance = 5>>								/* leader has a base chance of 5% to get wounded */
<<set _tacChance = 0.5>> 								/* by default tactics have a 50% chance of succeeding */
<<set _expBonus = 0>>
<<set _loyaltyBonus = 0>>
<<set _irregularMod = 0>>
<<set _armyMod = 0>>

/* calculates PC army stats */
<<if $engageRule == 0>>
	<<set _engageMod = 0.5>>
<<elseif $engageRule == 1>>
	<<set _engageMod = 0.75>>
<<elseif $engageRule == 2>>
	<<set _engageMod = 1>>
<<else>>
	<<set _engageMod = 1.4>>
<</if>>

<<if $week <= 30>>
	<<set _irregularMod = $irregulars / 60>>
<<elseif $week <= 60>>
	<<set _irregularMod = $irregulars / 50>>
<<elseif $week <= 90>>
	<<set _irregularMod = $irregulars / 40>>
<<elseif $week <= 120>>
	<<set _irregularMod = $irregulars / 30>>
<<else>>
	<<set _irregularMod = $irregulars / 20>>
<</if>>
<<if $irregulars > 0>>
	<<set $deployingMilitia = 1>>
	<<set _irregularMod = Math.trunc(_irregularMod)>>
	<<set _attack += (($militiaBaseAttack - $humanUpgrade.attack) + ($militiaBaseAttack - $humanUpgrade.attack) * $attackEquip * $equipMod) * _irregularMod * 0.80>>
	<<set _defense += (($militiaBaseDefense - $humanUpgrade.defense) + ($militiaBaseDefense - $humanUpgrade.defense) * $attackEquip * $equipMod) * _irregularMod * 0.80>>
	<<set _hp += $militiaBaseHp * $irregulars>>
<</if>>

<<if $secBots.active == 1>>
	<<set _attack += ($secBotsBaseAttack + $secBotsBaseAttack * $secBots.equip * $equipMod)>>
	<<set _defense += ($secBotsBaseDefense + $secBotsBaseDefense * $secBots.equip * $equipMod)>>
	<<set _hp += $secBotsBaseHp * $secBots.troops>>
	<<set $deployedUnits++>>
<</if>>

<<for _i = 0; _i < $militiaUnits.length; _i++>>
	<<if $militiaUnits[_i].active == 1 && $loyalID.includes($militiaUnits[_i].ID)>>
		<<set $deployingMilitia = 1>>
		<<set $deployedUnits++>>
		<<if $militiaUnits[_i].training <= 10>>
			<<set _expBonus = 0>>
		<<elseif $militiaUnits[_i].training <= 33>>
			<<set _expBonus = 0.10>>
		<<elseif $militiaUnits[_i].training <= 66>>
			<<set _expBonus = 0.25>>
		<<else>>
			<<set _expBonus = 0.50>>
		<</if>>
		<<if $militiaUnits[_i].loyalty <= 10>>
			<<set _loyaltyBonus = 0>>
		<<elseif $militiaUnits[_i].loyalty <= 33>>
			<<set _loyaltyBonus = 0.10>>
		<<elseif $militiaUnits[_i].loyalty <= 66>>
			<<set _loyaltyBonus = 0.20>>
		<<else>>
			<<set _loyaltyBonus = 0.30>>
		<</if>>
		<<set _attack += ($militiaBaseAttack + $militiaBaseAttack * $militiaUnits[_i].equip * $equipMod + $militiaBaseAttack * _expBonus + $militiaBaseAttack * _loyaltyBonus + $militiaBaseAttack * $militiaUnits[_i].SF * 0.20 + $militiaUnits[_i].cyber)>>
		<<set _defense += ($militiaBaseDefense + $militiaBaseDefense * $militiaUnits[_i].equip * $equipMod + $militiaBaseDefense * _expBonus + $militiaBaseDefense * _loyaltyBonus + $militiaBaseDefense * $militiaUnits[_i].SF * 0.20 + $militiaUnits[_i].cyber)>>
		<<set _hp += ($militiaBaseHp + $militiaUnits[_i].cyber + $militiaBaseHp * $militiaUnits[_i].medics * 0.25) * $militiaUnits[_i].troops>>
	<</if>>
<</for>>
<<for _i = 0; _i < $slaveUnits.length; _i++>>
	<<if $slaveUnits[_i].active == 1 && $loyalID.includes($slaveUnits[_i].ID)>>
		<<set $deployingSlaves = 1>>
		<<set $deployedUnits++>>
		<<if $slaveUnits[_i].training <= 33>>
			<<set _expBonus = 0>>
		<<elseif $slaveUnits[_i].training <= 66>>
			<<set _expBonus = 0.25>>
		<<else>>
			<<set _expBonus = 0.50>>
		<</if>>
		<<if $slaveUnits[_i].loyalty <= 10>>
			<<set _loyaltyBonus = 0>>
		<<elseif $slaveUnits[_i].loyalty <= 33>>
			<<set _loyaltyBonus = 0.10>>
		<<elseif $slaveUnits[_i].loyalty <= 66>>
			<<set _loyaltyBonus = 0.20>>
		<<else>>
			<<set _loyaltyBonus = 0.30>>
		<</if>>
		<<set _attack += ($slaveBaseAttack + $slaveBaseAttack * $slaveUnits[_i].equip * $equipMod + $slaveBaseAttack * _expBonus + $slaveBaseAttack * _loyaltyBonus + $slaveBaseAttack * $slaveUnits[_i].SF * 0.20 + $slaveUnits[_i].cyber)>>
		<<set _defense += ($slaveBaseDefense + $slaveBaseDefense * $slaveUnits[_i].equip * $equipMod + $slaveBaseDefense * _expBonus + $slaveBaseDefense * _loyaltyBonus + $slaveBaseDefense * $slaveUnits[_i].SF * 0.20 + $slaveUnits[_i].cyber)>>
		<<set _hp += ($slaveBaseHp + $slaveUnits[_i].cyber + $slaveBaseHp * $slaveUnits[_i].medics * 0.25) * $slaveUnits[_i].troops>>
	<</if>>
<</for>>
<<for _i = 0; _i < $mercUnits.length; _i++>>
	<<if $mercUnits[_i].active == 1 && $loyalID.includes($mercUnits[_i].ID)>>
		<<set $deployingMercs = 1>>
		<<set $deployedUnits++>>
		<<if $mercUnits[_i].training <= 33>>
			<<set _expBonus = 0>>
		<<elseif $mercUnits[_i].training <= 66>>
			<<set _expBonus = 0.25>>
		<<else>>
			<<set _expBonus = 0.50>>
		<</if>>
		<<if $mercUnits[_i].loyalty <= 10>>
			<<set _loyaltyBonus = 0>>
		<<elseif $mercUnits[_i].loyalty <= 33>>
			<<set _loyaltyBonus = 0.10>>
		<<elseif $mercUnits[_i].loyalty <= 66>>
			<<set _loyaltyBonus = 0.20>>
		<<else>>
			<<set _loyaltyBonus = 0.30>>
		<</if>>
		<<set _attack += ($mercBaseAttack + $mercBaseAttack * $mercUnits[_i].equip * $equipMod + $mercBaseAttack * _expBonus + $mercBaseAttack * _loyaltyBonus + $mercBaseAttack * $mercUnits[_i].SF * 0.20 + $mercUnits[_i].cyber)>>
		<<set _defense += ($mercBaseDefense + $mercBaseDefense * $mercUnits[_i].equip * $equipMod + $mercBaseDefense * _expBonus + $mercBaseDefense * _loyaltyBonus + $mercBaseDefense * $mercUnits[_i].SF * 0.20 + $mercUnits[_i].cyber)>>
		<<set _hp += ($mercBaseHp + $mercUnits[_i].cyber + $mercBaseHp * $mercUnits[_i].medics * 0.25) * $mercUnits[_i].troops>>
	<</if>>
<</for>>

<<if $securityForceCreate == 1>>
	<<set $SFatk = 0>>
	<<set $SFdef = 0>>
	<<set $SFhp = 0>>
	<<calcSFStatistics>>
	<<set _attack += $SFatk>>
	<<set _defense += $SFdef>>
	<<set _hp += $SFhp>>

<</if>>

<<set _attack *= _engageMod>>
<<set _defense *= _engageMod>>
<<set _hp *= _engageMod>>

<<if $garrison.assistant == 1>>
	<<set _attack *= 0.95>>
	<<set _defense *= 0.95>>
	<<set _hp *= 0.95>>
<</if>>
<<if $garrison.reactor == 1>>
	<<set _attack *= 0.95>>
	<<set _defense *= 0.95>>
	<<set _hp *= 0.95>>
<</if>>
<<if $garrison.penthouse == 1>>
	<<set _attack *= 0.95>>
	<<set _defense *= 0.95>>
	<<set _hp *= 0.95>>
<</if>>
<<if $garrison.waterway == 1>>
	<<set _attack *= 0.95>>
	<<set _defense *= 0.95>>
	<<set _hp *= 0.95>>
<</if>>

<<set $troopCount = 0>>
<<calcTroopCount>>
<<set _moraleTroopMod = Math.clamp($troopCount / 100,1,10)>>

/* morale and baseHp calculation */
<<set _morale = ($secBotsMorale * $secBots.active + $militiaBaseMorale * $deployingMilitia + $slaveBaseMorale * $deployingSlaves + $mercBaseMorale * $deployingMercs + $SFBaseMorale * $securityForceCreate) / ($secBots.active + $deployingMilitia +$deployingSlaves + $deployingMercs + $securityForceCreate)>>
<<set _morale = _morale + _morale * $secBarracksUpgrades.luxury * 0.05>>	/* barracks bonus */
<<set _morale *= _moraleTroopMod>>
<<set _baseHp = ($secBotsBaseHp * $secBots.active + $militiaBaseHp * $deployingMilitia + $slaveBaseHp * $deployingSlaves + $mercBaseHp * $deployingMercs + $SFBaseHp * $securityForceCreate) / ($secBots.active + $deployingMilitia +$deployingSlaves + $deployingMercs + $securityForceCreate)>>

/* calculates rebelling army stats */
<<if $week <= 30>>
	<<set _armyMod = $attackTroops / 100>>
<<elseif $week <= 60>>
	<<set _armyMod = $attackTroops / 90>>
<<elseif $week <= 90>>
	<<set _armyMod = $attackTroops / 80>>
<<elseif $week <= 120>>
	<<set _armyMod = $attackTroops / 70>>
<<else>>
	<<set _armyMod = $attackTroops / 60>>
<</if>>
<<set _armyMod = Math.trunc(_armyMod)>>

<<if $slaveRebellion == 1>>
	<<set $rebellingSlaves = 1>>
	<<set _enemyAttack += (($slaveBaseAttack - $humanUpgrade.attack) + ($slaveBaseAttack - $humanUpgrade.attack) * $attackEquip * $equipMod) * _armyMod>>
	<<set _enemyDefense += (($slaveBaseDefense - $humanUpgrade.defense) + ($slaveBaseDefense - $humanUpgrade.defense) * $attackEquip * $equipMod) * _armyMod>>
	<<set _enemyHp += $slaveBaseHp * $attackTroops>>
<<else>>
	<<set $rebellingMilitia = 1>>
	<<set _enemyAttack += (($militiaBaseAttack - $humanUpgrade.attack) + ($militiaBaseAttack - $humanUpgrade.attack) * $attackEquip * $equipMod) * _armyMod>>
	<<set _enemyDefense += (($militiaBaseDefense - $humanUpgrade.defense) + ($militiaBaseDefense - $humanUpgrade.defense) * $attackEquip * $equipMod) * _armyMod>>
	<<set _enemyHp += $militiaBaseHp * $attackTroops>>
<</if>>

<<for _i = 0; _i < $militiaUnits.length; _i++>>
	<<if $militiaUnits[_i].active == 1 && $rebellingID.includes($militiaUnits[_i].ID)>>
		<<set $rebellingMilitia = 1>>
		<<set $attackTroops += $militiaUnits[_i].troops>>
		<<if $militiaUnits[_i].training <= 10>>
			<<set _expBonus = 0>>
		<<elseif $militiaUnits[_i].training <= 33>>
			<<set _expBonus = 0.10>>
		<<elseif $militiaUnits[_i].training <= 66>>
			<<set _expBonus = 0.25>>
		<<else>>
			<<set _expBonus = 0.50>>
		<</if>>
		<<set _enemyAttack += ($militiaBaseAttack + $militiaBaseAttack * $militiaUnits[_i].equip * $equipMod + $militiaBaseAttack * _expBonus + $militiaBaseAttack * $militiaUnits[_i].SF * 0.20 + $militiaUnits[_i].cyber)>>
		<<set _enemyDefense += ($militiaBaseDefense + $militiaBaseDefense * $militiaUnits[_i].equip * $equipMod + $militiaBaseDefense * _expBonus + $militiaBaseDefense * $militiaUnits[_i].SF * 0.20 + $militiaUnits[_i].cyber)>>
		<<set _enemyHp += ($militiaBaseHp + $militiaUnits[_i].cyber + $militiaBaseHp * $militiaUnits[_i].medics * $equipMod) * $militiaUnits[_i].troops>>
	<</if>>
<</for>>
<<for _i = 0; _i < $slaveUnits.length; _i++>>
	<<if $slaveUnits[_i].active == 1 && $rebellingID.includes($slaveUnits[_i].ID)>>
		<<set $rebellingSlaves = 1>>
		<<set $attackTroops += $slaveUnits[_i].troops>>
		<<if $slaveUnits[_i].training <= 33>>
			<<set _expBonus = 0>>
		<<elseif $slaveUnits[_i].training <= 66>>
			<<set _expBonus = 0.25>>
		<<else>>
			<<set _expBonus = 0.50>>
		<</if>>
		<<set _enemyAttack += ($slaveBaseAttack + $slaveBaseAttack * $slaveUnits[_i].equip * $equipMod + $slaveBaseAttack * _expBonus + $slaveBaseAttack * $slaveUnits[_i].SF * 0.20 + $slaveUnits[_i].cyber)>>
		<<set _enemyDefense += ($slaveBaseDefense + $slaveBaseDefense * $slaveUnits[_i].equip * $equipMod + $slaveBaseDefense * _expBonus + $slaveBaseDefense * $slaveUnits[_i].SF * 0.20 + $slaveUnits[_i].cyber)>>
		<<set _enemyHp += ($slaveBaseHp + $slaveUnits[_i].cyber + $slaveBaseHp * $slaveUnits[_i].medics * 0.25) * $slaveUnits[_i].troops>>
	<</if>>
<</for>>
<<for _i = 0; _i < $mercUnits.length; _i++>>
	<<if $mercUnits[_i].active == 1 && $rebellingID.includes($mercUnits[_i].ID)>>
		<<set $rebellingMercs = 1>>
		<<set $attackTroops += $mercUnits[_i].troops>>
		<<if $mercUnits[_i].training <= 33>>
			<<set _expBonus = 0>>
		<<elseif $mercUnits[_i].training <= 66>>
			<<set _expBonus = 0.25>>
		<<else>>
			<<set _expBonus = 0.50>>
		<</if>>
		<<set _enemyAttack += ($mercBaseAttack + $mercBaseAttack * $mercUnits[_i].equip * $equipMod + $mercBaseAttack * _expBonus + $mercBaseAttack * $mercUnits[_i].SF * 0.20 + $mercUnits[_i].cyber)>>
		<<set _enemyDefense += ($mercBaseDefense + $mercBaseDefense * $mercUnits[_i].equip * $equipMod + $mercBaseDefense * _expBonus + $mercBaseDefense * $mercUnits[_i].SF * 0.20 + $mercUnits[_i].cyber)>>
		<<set _enemyHp += ($mercBaseHp + $mercUnits[_i].cyber + $mercBaseHp * $mercUnits[_i].medics * 0.25) * $mercUnits[_i].troops>>
	<</if>>
<</for>>

<<set _enemyMoraleTroopMod = Math.clamp($attackTroops / 100,1,10)>>

<<set _enemyMorale = 1.5 * ($militiaBaseMorale * $rebellingMilitia + $slaveBaseMorale * $rebellingSlaves + $mercBaseMorale * $rebellingMercs) / ($rebellingMilitia + $rebellingSlaves + $rebellingMercs)>>
<<set _enemyMorale *= _enemyMoraleTroopMod>>
<<set _enemyBaseHp = ($militiaBaseHp * $rebellingMilitia + $slaveBaseHp * $rebellingSlaves + $mercBaseHp * $rebellingMercs) / ($rebellingMilitia +$rebellingSlaves + $rebellingMercs)>>

<<if isNaN(_attack)>>

@@.red;Error: attack value reported NaN@@
<</if>>
<<if isNaN(_defense)>>

@@.red;Error: defense value reported NaN@@
<</if>>
<<if isNaN(_hp)>>

@@.red;Error: hp value reported NaN@@
<</if>>
<<if isNaN(_morale)>>

@@.red;Error: morale value reported NaN@@
<</if>>
<<if isNaN(_enemyAttack)>>

@@.red;Error: enemy attack value reported NaN@@
<</if>>
<<if isNaN(_enemyDefense)>>

@@.red;Error: enemy defense value reported NaN@@
<</if>>
<<if isNaN(_enemyHp)>>

@@.red;Error: enemy hp value reported NaN@@
<</if>>
<<if isNaN(_enemyMorale)>>

@@.red;Error: enemy morale value reported NaN@@
<</if>>

/* difficulty */
<<set _enemyAttack *= $difficulty>>
<<set _enemyDefense *= $difficulty>>
<<set _enemyMorale *= $difficulty>>
<<set _enemyHp *= $difficulty>>
<<set _enemyBaseHp *= $difficulty>>

<<if $showBattleStatistics == 1>>
<<set _engageMod -= 1>>
<<set _engageMod = Math.round(_engageMod * 100)>>
<<set _difficulty = ($difficulty -1) * 100>>

__Difficulty__:

<<if $difficulty == 0.5>>
	Very easy
<<elseif $difficulty == 0.75>>
	Easy
<<elseif $difficulty == 1>>
	Normal
<<elseif $difficulty == 1.25>>
	Hard
<<else>>
	Very hard
<</if>>

__Army__:

troops: <<print $troopCount>>

attack: <<print Math.round(_attack)>>

defense: <<print Math.round(_defense)>>

engagement rule modifier: <<if _engageMod > 0>>+<</if>><<print _engageMod>>%

Hp: <<print Math.round(_hp)>>

base HP: <<print Math.round(_baseHp)>>

morale: <<print Math.round(_morale)>>
<<if _enemyMoraleTroopMod > 0>>

morale increase due to troop numbers: +<<print _moraleTroopMod>>%
<</if>>

__Rebels__:

enemy troops: <<print $attackTroops>>

enemy attack: <<print Math.round(_enemyAttack)>>

enemy defense: <<print Math.round(_enemyDefense)>>

enemy Hp: <<print Math.round(_enemyHp)>>

enemy base Hp: <<print Math.round(_enemyBaseHp)>>

enemy morale: <<print Math.round(_enemyMorale)>>
<<if _enemyMoraleTroopMod > 0>>

enemy morale increase due to troop numbers: +<<print _enemyMoraleTroopMod>>%
<</if>>

Difficulty modifier: <<if _difficulty > 0>>+<</if>><<print _difficulty>>%
<</if>>

/* simulates the combat by pitting attk against def */
<<for _i = 0; _i < _turns; _i++>>

	<<if $showBattleStatistics == 1>> turn: <<print _i + 1>><</if>>
	/* player army attacks */
	<<set _damage = Math.clamp(_attack - _enemyDefense,_attack * 0.1,_attack)>>

	<<if $showBattleStatistics == 1>> player damage: <<print Math.round(_damage)>><</if>>
	<<set _enemyHp -= _damage>>

	<<if $showBattleStatistics == 1>> remaining enemy Hp: <<print Math.round(_enemyHp)>><</if>>
	<<set $enemyLosses += _damage / _enemyBaseHp>>
	<<set _moraleDamage = Math.clamp(_damage/ 2 + _damage / _enemyBaseHp,0,_damage*1.5)>>
	<<set _enemyMorale -= _moraleDamage>>

	<<if $showBattleStatistics == 1>> remaining enemy morale: <<print Math.round(_enemyMorale)>><</if>>
	<<if _enemyHp <= 0 || _enemyMorale <= 0>>
		<<if $showBattleStatistics == 1>>
Victory!<</if>>
		<<set $battleResult = 3>>
		<<set $battleTurns = _i>>
		<<break>>
	<</if>>

	/* attacker army attacks */
	<<set _damage = _enemyAttack - _defense>>
	<<if _damage < _enemyAttack * 0.1>>
		<<set _damage = _enemyAttack * 0.1>>
	<</if>>

	<<if $showBattleStatistics == 1>> enemy damage: <<print Math.round(_damage)>><</if>>
	<<set _hp -= _damage>>

	<<if $showBattleStatistics == 1>> remaining hp: <<print Math.round(_hp)>><</if>>
	<<set $losses += _damage / _baseHp>>
	<<set _moraleDamage = Math.clamp(_damage / 2 + _damage / _baseHp,0,_damage*1.5)>>
	<<set _morale -= _moraleDamage>>

	<<if $showBattleStatistics == 1>> remaining morale: <<print Math.round(_morale)>><</if>>
	<<if _hp <= 0 || _morale <= 0>>
		<<if $showBattleStatistics == 1>>
Defeat!<</if>>
		<<set $battleResult = -3>>
		<<set $battleTurns = _i>>
		<<break>>
	<</if>>
<</for>>
<<if $battleResult != 3 && $battleResult != -3>>
	<<if _morale > _enemyMorale>>
		<<if $showBattleStatistics == 1>>
Partial victory!<</if>>
		<<set $battleResult = 2>>
	<<elseif _morale < _enemyMorale>>
		<<if $showBattleStatistics == 1>>
Partial defeat!<</if>>
		<<set $battleResult = -2>>
	<</if>>
<</if>>

<<if $battleResult > 3 || $battleResult < -3>>

@@.red;Error: failed to determine battle result@@
<</if>>

<<if $showBattleStatistics == 1 && $rebellionGameOver == 1 && $battleResult == -3>>

	<<link "Proceed">>
		<<set $gameover = "Rebellion defeat">>
		<<goto "Gameover">>
	<</link>>
<<elseif $rebellionGameOver == 1 && $battleResult == -3>>
	<<set $gameover = "Rebellion defeat">>
	<<goto "Gameover">>
<<elseif $showBattleStatistics == 1>>

	<<link "Proceed">>
		<<goto "rebellionReport">>
	<</link>>
<<else>>
	<<goto "rebellionReport">>
<</if>>