code:
:: Farm Upgrades
<<effects>>
<<farm_work_update>>
<<if $farm_work.alex is "admin" or ($farm_work.alex is "clearing" and $farm_stage is 12)>>
	You sit beside Alex, and look through the ways the farm could be improved.

<<else>>
	You sit at the desk, and look through the ways the farm could be improved.

<</if>>

<<farm_upgrades_current>>
<<set _upgrade_count to 0>>
Wall:
<<if $farm.wall gte 4 or $farm.build is "wall 4">>
	As sturdy as can be
	<<set _upgrade_count += 1>>
<<elseif $farm.wall is 3 or $farm.build is "wall 3">>
	<<link [[Barbed wire|Farm Upgrades Wall 4]]>><</link>>
<<elseif $farm.wall is 2 or $farm.build is "wall 2">>
	<<link [[Metal fence|Farm Upgrades Wall 3]]>><</link>>
<<elseif $farm.wall is 1 or $farm.build is "wall 1">>
	<<link [[Reinforce|Farm Upgrades Wall 2]]>><</link>>
<<else>>
	<<link [[Full repair|Farm Upgrades Wall 1]]>><</link>>
<</if>>

<<if $farm_stage gte 8>>
	Security:
	<<if $farm.tower is 2 or $farm.build is "tower 2">>
		As watchful as can be
		<<set _upgrade_count += 1>>
	<<elseif $farm.tower is 1 or $farm.build is "tower 1">>
		<<link [[Searchlights|Farm Upgrades Tower 2]]>><</link>>
	<<else>>
		<<link [[Watchtower|Farm Upgrades Tower]]>><</link>>
	<</if>>

	Woodland:
	<<if $farm.woodland gte 3 or $farm.build is "woodland 3">>
		Annexed by the farm
		<<set _upgrade_count += 1>>
	<<elseif $farm.woodland gte 2 or $farm.build is "woodland 2">>
		<<link [[Purchase even more|Farm Upgrades Woodland 3]]>><</link>>
	<<elseif $farm.woodland gte 1 or $farm.build is "woodland 1">>
		<<link [[Purchase more|Farm Upgrades Woodland 2]]>><</link>>
	<<else>>
		<<link [[Purchase|Farm Upgrades Woodland 1]]>><</link>>
	<</if>>

	Kennel:
	<<if $farm.kennel gte 1 or $farm.build is "kennel 1">>
		State of the art
		<<set _upgrade_count += 1>>
	<<else>>
		<<link [[Outfit with training facilities|Farm Upgrades Kennel 1]]>><</link>>
	<</if>>

	Barn:
	<<if $farm.barn gte 2 or $farm.build is "barn 2">>
		As robust as can be
		<<set _upgrade_count += 1>>
	<<elseif $farm.barn gte 1 or $farm.build is "barn 1">>
		<<link [[Expand|Farm Upgrades Barn 2]]>><</link>>
	<<else>>
		<<link [[Outfit with new milking equipment|Farm Upgrades Barn 1]]>><</link>>
	<</if>>

	Stable:
	<<if $farm.stable gte 1 or $farm.build is "stable 1">>
		As sophisticated as can be
		<<set _upgrade_count += 1>>
	<<else>>
		<<link [[Expand|Farm Upgrades Stable 1]]>><</link>>
	<</if>>

	Coop:
	<<if $farm.coop gte 2 or $farm.build is "coop 2">>
		As big as can be
		<<set _upgrade_count += 1>>
	<<elseif $farm.coop gte 1 or $farm.build is "coop 1">>
		<<link [[Expand again|Farm Upgrades Coop 2]]>><</link>>
	<<else>>
		<<link [[Expand|Farm Upgrades Coop 1]]>><</link>>
	<</if>>

	Farm Irrigation:
	<<if $farm.irrigation gte 9>>
		Every field has irrigation
		<<set _upgrade_count += 1>>
	<<elseif $farm.irrigation is $plots.farm.length>>
		Every current field has irrigation
	<<else>>
		<<link [[Build field irrigation|Farm Upgrades Irrigation]]>><</link>>
	<</if>>

	<<if $sexStats.anus.pregnancy.motherStatus gte 1 and ($farm.parasitebarn gte 1 or $farm.build is "parasites 1")>>
		Parasite Barn:
		<<if $farm.parasitebarn gte 2 or $farm.build is "parasites 2">>
			As big as can be
		<<else>>
			<<link [[Expand|Farm Upgrades Parasite Barn 2]]>><</link>>
		<</if>>

	<</if>>

<</if>>

<<if $sexStats.anus.pregnancy.motherStatus gte 1 and !$farm.parasitebarn and $farm.build isnot "parasites 1">>
	Your thoughts drift to the various critters you've given birth to. The farm has everything you'd need to care for them. An idea strikes you.

	<<link [[Build a barn for your parasites|Farm Upgrades Parasite Barn]]>><</link>>

<</if>>
<<if !$alex_greenhouse>>
	There's a crumpled piece of paper in the nearby bin, covered in red ink.

	<<link [[Examine|Farm Upgrades Greenhouse]]>><</link>>

<</if>>

<<if _upgrade_count gte 8>>
	<<earnFeat "The Rival Estate">>
<</if>>
<<if _upgrade_count gte 1>>
	<<earnFeat "The Rival Farm">>
<</if>>

<<link [[Leave|Farm Alex Bedroom]]>><</link>>

:: Farm Upgrades Greenhouse
<<effects>>

You unfurl the paper. The details have been crossed out, but it looks like plans for a greenhouse.

<<if $farm_work.alex is "admin" or ($farm_work.alex is "clearing" and $farm_stage is 12)>>
	<<npc Alex>><<person1>>
	<<if $NPCName[$NPCNameList.indexOf("Alex")].love gte 80>>
		Alex takes it, and sighs. "I thought a greenhouse might be more managable for me," <<he>> says. "Growing herbs and flowers just as a hobby. Drew up all the plans, but I don't think I'd have time."

		It looks like it would fit the orphanage garden. You could build this and an expansion for the farm at the same time.

		<<if $money gte 1000000>>
			<<link [[Build (£10000)|Farm Upgrades Greenhouse 2]]>><<set $alex_greenhouse to 1>><<set $alex_greenhouse_timer to 7>><<set $money -= 1000000>><</link>>

		<<else>>
			You don't have enough money to build the greenhouse.

		<</if>>

		<<link [[Back|Farm Upgrades]]>><<endevent>><</link>>

	<<else>>
		Alex snatches it, and scoffs. "This isn't important," <<he>> says, crumpling it back up. "I was just wasting time."

		<<He>> might open up if <<he>> felt more comfortable around you.

		<<link [[Next|Farm Upgrades]]>><<endevent>><</link>>

	<</if>>
<<else>>
	<<npc Alex>><<person1>>
	You could ask Alex about it the next time you catch <<him>> doing admin work here.

	<<link [[Next|Farm Upgrades]]>><<endevent>><</link>>

<</if>>

:: Farm Upgrades Greenhouse 2
<<effects>>

<<if $submissive gte 1150>>
	"C-could I suggest something?" you ask. "I think my friends back at the orphanage would like this. We have a garden-"
<<elseif $submissive lte 850>>
	"I've got an idea," you say. "I could use your plans for the orphanage. The orphans would-"
<<else>>
	"I've got an idea," you say. "The orphanage could use a greenhouse. Is it okay if I use your plans-"
<</if>>

"That's a great idea," Alex interrupts, smiling. "Maybe I wasn't wasting my time." <<He>> flattens the paper further, and points out a number near the top.

You make the call. They'll begin building at once.

<<link [[Next|Farm Upgrades]]>><<endevent>><</link>>

:: Farm Upgrades Wall 1
<<effects>>

The stone wall surrounding the farm is old, and has vanished in places. Repairing these sections properly might deter intruders.

Slightly slows Remy's encroachment.

Slightly slows attackers during an assault.

Costs £3500.

Will take a week to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 350000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 350000>><<set $farm.build to "wall 1">><<set $farm.build_timer to 7>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Build
<<effects>>

You make the call. They'll start work at once.

<<link [[Next|Farm Upgrades]]>><</link>>

:: Farm Upgrades Wall 2
<<effects>>

The wall is sturdy, but could be stronger still. Reinforcing it with cement would make it harder to sabotage.

Reduces the impact of Sabotage, making the wall easier to maintain.

Further slows attackers during an assault.

Costs £10000.

Will take a week to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 1000000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 1000000>><<set $farm.build to "wall 2">><<set $farm.build_timer to 7>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Wall 3
<<effects>>

A metal fence could be built atop the stone perimeter. It would take more effort to climb.

Thwarts some intrusion attempts.

Further slows attackers during an assault.

Costs £25000.

Will take two weeks to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 2500000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 2500000>><<set $farm.build to "wall 3">><<set $farm.build_timer to 14>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Wall 4
<<effects>>

The fence could be crowned with barbed wire, making it impossible to climb without special equipment.

Thwarts many intrusion attempts.

Further slows attackers during an assault.

Costs £5000.

Will take a week to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 500000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 500000>><<set $farm.build to "wall 4">><<set $farm.build_timer to 7>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Tower
<<effects>>

A tower could be built to watch over the fields at night. You'll need to employ someone to staff it.

Slows Remy's encroachment.

Gives information during assaults.

Needs to be staffed to fully function.

Costs £20000.

Will take two weeks to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 2000000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 2000000>><<set $farm.build to "tower 1">><<set $farm.build_timer to 14>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Tower 2
<<effects>>

Searchlights could be affixed to the watchtower, making security more effective.

Further slows Remy's encroachment.

Makes spotting during assaults easier.

Only functions while staffed.

Costs £5000.

Will take a week to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 500000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 500000>><<set $farm.build to "tower 2">><<set $farm.build_timer to 7>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Woodland 1
<<effects>>

Woodland surrounds much of the farm, and could be annexed to give the swine more room to root.

Increases truffles produced.

Needs to be managed.

More freedom will make the swine harder to control.

Costs £10000.

Will take three days to extend the fence.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 1000000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 1000000>><<set $farm.build to "woodland 1">><<set $farm.build_timer to 3>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Woodland 2
<<effects>>

Some of the nearby woodland is fat with fruit, nuts and edible mushrooms. Annexing it will add a space to forage.

Lets you forage on the farm.

Needs to be managed.

Costs £20000.

Will take five days to extend the fence.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 2000000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 2000000>><<set $farm.build to "woodland 2">><<set $farm.build_timer to 5>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Woodland 3
<<effects>>

Even more woodland could be annexed, giving you and the swine more room to forage.

Increases truffles produced.

Increases forage produced.

Needs to be managed.

More freedom will make the swine harder to control.

Costs £50000.

Will take a week to extend the fence.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 5000000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 5000000>><<set $farm.build to "woodland 3">><<set $farm.build_timer to 7>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Kennel 1
<<effects>>

The kennel could be outfitted with facilities for training guard dogs, letting your hounds help with farm security.

Slows Remy's encroachment.

The hounds will be more disciplined during assaults.

Adds a new option to the kennel.

Training the hounds to take down humans will make them harder to control.

The aggression will agitate the cattle as well.

Costs £15000.

Will take a week to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 1500000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 1500000>><<set $farm.build to "kennel 1">><<set $farm.build_timer to 7>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Stable 1
<<effects>>

The stable could be expanded to give the horses more space, improving their rest.

Steeds will carry you to and from town faster.

Costs £20000.

Will take two weeks to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 2000000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 2000000>><<set $farm.build to "stable 1">><<set $farm.build_timer to 14>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Barn 1
<<effects>>

State of the art milking equipment could be installed in the barn, increasing your yield.

More milk from your cattle.

Lets you milk yourself faster.

Costs £5000.

Will take two days to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 500000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 500000>><<set $farm.build to "barn 1">><<set $farm.build_timer to 2>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Barn 2
<<effects>>

A bigger barn means room for more cattle.

More cattle, and more milk.

More time spent milking.

Costs £20000.

Will take ten days to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 2000000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 2000000>><<set $farm.build to "barn 2">><<set $farm.build_timer to 10>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Coop 1
<<effects>>

A bigger coop means room for more chickens.

More eggs produced.

Costs £2000.

Will take five days to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 200000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 200000>><<set $farm.build to "coop 1">><<set $farm.build_timer to 5>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Coop 2
<<effects>>

An even bigger coop means even more chickens.

Even more eggs produced.

Costs £5000.

Will take a week to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 500000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 500000>><<set $farm.build to "coop 2">><<set $farm.build_timer to 7>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Parasite Barn

A new barn to store your parasites.

Parasite Storage.

Costs £5000.

Will take 2 weeks to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 500000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 500000>><<set $farm.build to "parasites 1">><<set $farm.build_timer to 14>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Parasite Barn 2

A new barn to store your parasites.

Upgrades the Parasite barn, providing a little extra space and allowing them to survive on their own for longer.

Costs £20000.

Will take a week to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 2000000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 2000000>><<set $farm.build to "parasites 2">><<set $farm.build_timer to 7>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>

:: Farm Upgrades Irrigation

Irrigation channels from the local river.

Adds irrigation to a field so that you no longer need to water the crops.

Costs £5000.

Will take three days to build.

There'll be workers on the farm until the project is completed.

<<if $farm.build>>
	Only one upgrade can be worked on at once.

<<elseif $money gte 500000>>
	<<link [[Build (0:20)|Farm Upgrades Build]]>><<pass 20>><<set $money -= 500000>><<set $farm.build to "irrigation">><<set $farm.build_timer to 3>><</link>>

<</if>>

<<link [[Back|Farm Upgrades]]>><</link>>