:: building widgets [nobr widget]

/%
Call as <<DisplayBuilding>>
Displays the arcology as a table.
Yes, I am aware this is horrible. If anyone can figure out how to get widgets to play nice with tables, or otherwise unfuck this, tell me and I'll implement it.
%/
<<widget "DisplayBuilding">>

<<set _Pass = passage()>>

<style>
	table.arcology {
		table-layout: fixed;
		text-align: center;
		border-collapse: separate;
		border-spacing: 5px;
		border-style: hidden;
		empty-cells: hide;
		width: 70%;
	}
	
	table.arcology td {
		margin: 1px;
	}
	
	table.arcology col {
		width: 8%;
	}
	
	table.arcology td {
		border: 5px solid transparent;
	}
	
    td#Empty            { border-color: lightgray; }
    td#Private          { border-color: red; }
    td#Shops            { border-color: thistle; }
    td#FSShops          { border-color: mediumpurple; }
    td#Brothel          { border-color: violet; }
    td#Club             { border-color: orchid; }
    td#Apartments       { border-color: limegreen; }
    td#DenseApartments  { border-color: seagreen; }
    td#LuxuryApartments { border-color: palegreen; }
    td#Markets          { border-color: mediumorchid; }
    td#CorporateMarket  { border-color: purple; }
    td#Arcade           { border-color: deeppink; }
    td#Pens             { border-color: goldenrod; }
    td#Pit              { border-color: orangered; }
    td#Manufacturing    { border-color: slategray; }
    td#Sweatshops       { border-color: gray; }
    td#Barracks         { border-color: olivedrab; }
    td#Penthouse        { border-color: teal; }
    td#Dairy            { border-color: white; }
</style>

<<script>>
/* This code only runs once per page load */
if(!Macro.has('sectorblock')) {
	/* Usage: <<sectorblock sector index "other text (optional)">> */
	Macro.add('sectorblock', {
		/*
		 * Add sector metadata here
		 *
		 * base:  Which passage the sector link goes to if owned. Defaults to the sector type. Unowned go to "Private"
		 * name:  The sector name. Defaults to the sector type, with spaces inserted in case of WordsLikeThis
		 * cls:   The CSS id to use for styling if owned; else uses "Private"
		 * extra: Some (SugarCube-style) extra text to add after the link
		 */
		sectors: {
			LuxuryApartments: { base: 'Apartments' },
			DenseApartments: { base: 'Apartments' },
			Club: { extra: ' ($clubSlaves/<<print $club>><<if $DJ>>, L<</if>>)' },
			Brothel: { extra: ' ($brothelSlaves/<<print $brothel>><<if $Madam>>,L<</if>>)' },
			CorporateMarket: { base: 'Corporate Market' },
			Pit: { extra: ' ($fighterIDs.length)'},
			Arcade: { extra: ' ($arcadeSlaves/<<print $arcade>>)'},
			Dairy: { extra: '<<set _SCapT9 = $bioreactorsXY+$bioreactorsXX+$bioreactorsHerm+$bioreactorsBarren>> ($dairySlaves<<if _SCapT9>>+_SCapT9<</if>>/<<print $dairy>><<if $Milkmaid>>,L<</if>>)' },
			Sweatshops: { base: 'Manufacturing' },
			Barracks: { base: 'Barracks', name: 'Armoury' },
			/* speciality shop types */
			'Subjugationist': { base: 'Shops', name: 'Subjugationist Shops', cls: 'FSShops' },
			'Supremacist': { base: 'Shops', name: 'Supremacist Shops', cls: 'FSShops' },
			'Gender Radicalist': { base: 'Shops', name: 'Gender Radicalist Shops', cls: 'FSShops' },
			'Gender Fundamentalist': { base: 'Shops', name: 'Gender Fundamentalist Shops', cls: 'FSShops' },
			'Paternalist': { base: 'Shops', name: 'Paternalist Shops', cls: 'FSShops' },
			'Degradationist': { base: 'Shops', name: 'Degradationist Shops', cls: 'FSShops' },
			'Body Purist': { base: 'Shops', name: 'Body Purist Shops', cls: 'FSShops' },
			'Transformation Fetishist': { base: 'Shops', name: 'Transformation Fetishist Shops', cls: 'FSShops' },
			'Youth Preferentialist': { base: 'Shops', name: 'Youth Preferentialist Shops', cls: 'FSShops' },
			'Maturity Preferentialist': { base: 'Shops', name: 'Maturity Preferentialist Shops', cls: 'FSShops' },
			'Slimness Enthusiast': { base: 'Shops', name: 'Slimness Enthusiast Shops', cls: 'FSShops' },
			'Asset Expansionist': { base: 'Shops', name: 'Asset Expansionist Shops', cls: 'FSShops' },
			'Pastoralist': { base: 'Shops', name: 'Pastoralist Shops', cls: 'FSShops' },
			'Physical Idealist': { base: 'Shops', name: 'Physical Idealist Shops', cls: 'FSShops' },
			'Chattel Religionist': { base: 'Shops', name: 'Chattel Religionist Shops', cls: 'FSShops' },
			'Roman Revivalist': { base: 'Shops', name: 'Roman Revivalist Shops', cls: 'FSShops' },
			'Aztec Revivalist': { base: 'Shops', name: 'Aztec Revivalist Shops', cls: 'FSShops' },
			'Egyptian Revivalist': { base: 'Shops', name: 'Egyptian Revivalist Shops', cls: 'FSShops' },
			'Edo Revivalist': { base: 'Shops', name: 'Edo Revivalist Shops', cls: 'FSShops' },
			'Arabian Revivalist': { base: 'Shops', name: 'Arabian Revivalist Shops', cls: 'FSShops' },
			'Chinese Revivalist': { base: 'Shops', name: 'Chinese Revivalist Shops', cls: 'FSShops' },
			'Repopulationist': { base: 'Shops', name: 'Repopulationist Shops', cls: 'FSShops' },
			'Eugenics': { base: 'Shops', name: 'Eugenics Shops', cls: 'FSShops' },
			'Hedonism': { base: 'Shops', name: 'Hedonistic Shops', cls: 'FSShops' },
		},
		
		handler() {
			let sec = this.args[0];
			if(!sec || !sec.type) {
				return;
			}
			let meta = this.self.sectors[sec.type] || {};
			let type = sec.ownership === 1 ? (meta.cls || sec.type) : 'Private';
			let basetype = sec.ownership === 1 ? (meta.base || sec.type) : 'Private';
			let name = meta.name || sec.type.replace(/([a-z])([A-Z])/g, '$1 $2');
			let text = 
				'<td colspan="2" id="' + type + '">'
				+ '[[' + name + '|' + basetype + '][$AS=' + this.args[1] + ']]'
				+ (meta.extra || '') + (this.args[2] || '')
				+ '</td>';
			new Wikifier(this.output, text);
		},
	});
}
<</script>>
<center>
<table class="arcology">
	<tr> /* Level 9, penthouse, sector 0 */
		<td colspan="3"></td>
		<td id="Penthouse" colspan="4">
			<<link "Penthouse">><<set $nextButton = "Back", $nextLink = _Pass>><<goto "Manage Penthouse">><</link>> @@.cyan;[P]@@
			<<if $masterSuite||$servantsQuarters||$spa||$clinic||$schoolroom||$cellblock||$incubator||$HGSuite||$researchLab.built=="true">>
				<br>
				<<if $masterSuite>>[[Suite|Master Suite]] ($masterSuiteSlaves/$masterSuite<<if $Concubine>>, C<</if>>)<</if>>
				<<if $servantsQuarters>>[[Quarters|Servants' Quarters]] ($servantsQuartersSlaves/$servantsQuarters<<if $Stewardess>>, L<</if>>)<</if>>
				<<if $spa>>[[Spa]] ($spaSlaves/$spa<<if $Attendant>>, L<</if>>)<</if>>
				<<if $clinic>>[[Clinic]] ($clinicSlaves/$clinic<<if $Nurse>>, L<</if>>)<</if>>
				<<if $schoolroom>>[[Schoolroom]] ($schoolroomSlaves/$schoolroom<<if $Schoolteacher>>, L<</if>>)<</if>>
				<<if $cellblock>>[[Cellblock]] ($cellblockSlaves/$cellblock<<if $Wardeness>>, L<</if>>)<</if>>
				<<if $incubator>>[[Incubator]] (<<if $incubator-$incubatorSlaves == 0>>No empty tanks<<elseif $incubator-$incubatorSlaves == 1>>1 empty tank<<else>><<print $incubator-$incubatorSlaves>> empty tanks<</if>>)<</if>>
				<<if $HGSuite>>[[HG Suite|Head Girl Suite]] ($HGSuiteSlaves)<</if>>
				<<if $researchLab.built == "true">>[[Research Lab][$temp = 0]]<</if>>
			<</if>>
		</td>
		<td colspan="3"></td>
	</tr>
	<<if $arcologyUpgrade.spire == 1>>
		<tr> /* Level 8, spire, sectors 1-2 */
			<td colspan="3"></td>
			<<for _i = 1; _i <= 2; _i++>><<sectorblock $sectors[_i] _i>><</for>>
			<td colspan="3"></td>
		</tr>
		<tr> /* Level 7, spire, sectors 3-4 */
			<td colspan="3"></td>
			<<for _i = 3; _i <= 4; _i++>><<sectorblock $sectors[_i] _i>><</for>>
			<td colspan="3"></td>
		</tr>
	<</if>>
	<tr> /* Level 6, promenade, sectors 5-7 */
		<td colspan="2"></td>
		<<for _i = 5; _i <= 7; _i++>><<sectorblock $sectors[_i] _i>><</for>>
		<td colspan="2"></td>
	</tr>
	<tr> /* Level 5, apartments, sectors 8-11 */
		<td></td>
		<<for _i = 8; _i <= 11; _i++>><<sectorblock $sectors[_i] _i>><</for>>
		<td></td>
	</tr>
	<tr> /* Level 4, apartments, sectors 12-15 */
		<td></td>
		<<for _i = 12; _i <= 15; _i++>><<sectorblock $sectors[_i] _i>><</for>>
		<td></td>
	</tr>
	<tr> /* Level 3, apartments, sectors 16-19 */
		<td></td>
		<<for _i = 16; _i <= 19; _i++>><<sectorblock $sectors[_i] _i>><</for>>
		<td></td>
	</tr>
	<tr> /* Level 2, concourse, sectors 20-24 */
		<<for _i = 20; _i <= 24; _i++>><<sectorblock $sectors[_i] _i>><</for>>
	</tr>
	<tr> /* Level 1, service area, sectors 25-29 */
		<<for _i = 25; _i <= 29; _i++>><<sectorblock $sectors[_i] _i>><</for>>
	</tr>
</table>
</center>

<</widget>>

<<widget "SectorSell">>

<<set $price = 1000*Math.trunc($arcologies[0].prosperity*(1+($arcologies[0].demandFactor/100)))>>
Selling this sector would relenquish a 4% interest in $arcologies[0].name. Such an interest is worth ¤$price.
<<if $arcologies[0].ownership >= 4>>
	[[Sell|Main][$cash += $price, $arcologies[0].ownership -= 4, $arcologies[0].demandFactor -= 20, $sectors[$AS].ownership = 0]]
<</if>>

<</widget>>

/%
 Call as <<SectorCounts>>
 Updates $ACitizenLimit, $ASlaveLimit, $AProsperityCap, $Sweatshops.
%/
<<widget "SectorCounts">>

<<if $arcologyUpgrade.drones != 1>>
	<<set $AProsperityCap = 0>>
<<elseif $arcologyUpgrade.hydro != 1>>
	<<set $AProsperityCap = 10>>
<<elseif $arcologyUpgrade.apron != 1>>
	<<set $AProsperityCap = 30>>
<<elseif $arcologyUpgrade.grid != 1>>
	<<set $AProsperityCap = 60>>
<<elseif $arcologyUpgrade.spire != 1>>
	<<set $AProsperityCap = 100>>
<<else>>
	<<set $AProsperityCap = 150>>
<</if>>
<<set $ACitizenLimit = 0, $ASlaveLimit = 0, $Sweatshops = 0>>
<<for _i = 8; _i <= 19; _i++>>
	<<if $sectors[_i].type == "DenseApartments">>
		<<set $ACitizenLimit += 600, $ASlaveLimit += 1000, $AProsperityCap += 10>>
	<<elseif $sectors[_i].type == "LuxuryApartments">>
		<<set $ACitizenLimit += 400, $ASlaveLimit += 2000, $AProsperityCap += 15>>
	<<else>>
		<<set $ACitizenLimit += 400, $ASlaveLimit += 1000, $AProsperityCap += 10>>
	<</if>>
<</for>>
<<for _i = 25; _i <= 29; _i++>>
	<<if $sectors[_i].type == "Sweatshops">>
		<<set $Sweatshops++>>
	<</if>>
<</for>>

<</widget>>

/%
 Call as <<UpdateOwnership>>
 Updates $arcologies[0].ownership.
%/
<<widget "UpdateOwnership">>

<<set $arcologies[0].ownership = 0>>
<<if $arcologyUpgrade.spire == 1>>
	<<for _i = 1; _i <= 29; _i++>>
		<<if $sectors[_i].ownership == 1>><<set $arcologies[0].ownership += 3.45>><</if>>
	<</for>>
	<<set $arcologies[0].ownership = Math.trunc($arcologies[0].ownership)>>
<<else>>
	<<for _i = 5; _i <= 29; _i++>>
		<<if $sectors[_i].ownership == 1>><<set $arcologies[0].ownership += 4>><</if>>
	<</for>>
<</if>>

<</widget>>
