:: agentned[public indoors]
/*<<set $here = 'agentned'>>
<<set $ARGS = $location_var[$here]>>
<<if $location_var[$here][0] == 'start'>>
	<<set $loc = 'agentned'>>
	<<set $loc_arg = $location_var[$here][0]>>
	<<set $location_type = 'indoors'>>
	<<set $menu_loc = 'agentned'>>
	<<set $menu_arg = 'start'>>
	<<set $menu_off = 0>>
	<<gs 'dina'>>
	<!-- !!	gs 'housing', 'rent'-->*/
	<<ConnectedLocation 'Leave' 'city_center' '' 'locations/city/citycenter/down.jpg' 5>>
	<h2>Kirsanova Real Estate Agency</h2>
	<<image "locations/city/citycenter/realestate/agenstvo.jpg">>
	This is the head office of the largest real estate agency in the Leningrad Oblast.
	/*At the reception, you notice a large print banner:
	<b>"Please be aware that all sales transactions are made exclusively through your bank account. Rent payments are excluded from this policy."</b>
	<<act 'View rentals'>>
		<<gt 'agentned' 'rent'>>
	<</act>>
	<<act 'View properties for sale'>>
		<<gt 'agentned' 'buy'>>
	<</act>>
	<!-- !! Get a list of the properties and their attributes that the player rented:-->
	<!-- !! Returns: $property_name[$i], $property_code[$i], $property_display[$i], property_rent[$i], property_days[$i]-->
	<<gs 'homes_properties' 'get_rented_properties' 'home'>>
	<<set $count = ARRSIZE('$property_name')>>
	<<if getvar("$count") > 0>>
		<<set $i = 0>>
		<h4>Rent Information</h4>
		<<warn 'JUMP MARKER ENCOUNTERED: :listing_rented_properties_loop'>>
		<!-- FAILED TO CONVERT
			'You have <B><<property_days[i]>> days</B> remaining on the lease of your <<$property_display[i]>>, and your monthly rent is <<func(''agentned'', ''format_price_string'', property_rent[i])>><b>₽</b>. '+iif(money >= property_rent[i],'You can make a rent <a href="exec:money -= <<property_rent[i]>> & gs ''homes_properties'', ''add_rental_days'', ''<<$property_code[i]>>'' & gt ''agentned'', ''start''">payment</a> in cash to extend it.','You can''t afford to pay your rent at the moment')
		-----
			<<set ERROR: FAILED TO CONVERT LITERAL: """'You have <B><<property_days[$i]>> days<""" / ERROR: FAILED TO CONVERT LITERAL: """B> remaining on the lease of your $property_display[$i]""" , ERROR: FAILED TO CONVERT LITERAL: """and your monthly rent is <<func(''agentned''""" , 'format_price_string' , ERROR: FAILED TO CONVERT LITERAL: """property_rent[$i])>><b>₽<""" / ERROR: FAILED TO CONVERT LITERAL: """b>. '""" + ERROR: FAILED TO CONVERT LITERAL: """iif(money >""" = $property_rent[$i] , ERROR: FAILED TO CONVERT LITERAL: """'You can make a rent <a href="exec:money""" - ERROR: FAILED TO CONVERT LITERAL: """= <<property_rent[$i]>>""">> <<gs 'homes_properties' 'add_rental_days' '$property_code[$i]'>> <<gt 'agentned' 'start'">payment</a> in cash to extend it.' 'You can't afford to pay your rent at the moment')>>

		-->
		<<warn "CONVERSION ERROR 69f513222de378b8391d0cb6e9970213">>
		<!-- !! TODO: Make the duplication way less.-->
		<<if $property_code[$i] == 'city_apartment'>>
			<<actCLA 'Cancel the lease of the $property_display['+$i]+''>>
				<!-- !! TODO: 1 month notice period like in real life?-->
				Attention: You won''t be able to return to your apartment when you cancel the lease.
				<<act 'Return'>>
					<<gt 'agentned' 'start'>>
				<</act>>
				<<actCLA 'Cancel it'>>
					<<gs 'homes_properties' 'cancel_rent' 'city_apartment'>> <<gt 'agentned' 'start'>>
				<</actCLA>>
			<</actCLA>>
		<<elseif $property_code[$i] == 'old_town_apartment'>>
			<<actCLA 'Cancel the lease of the $property_display['+$i]+''>>
				<!-- !! TODO: 1 month notice period like in real life?-->
				Attention: You won''t be able to return to your apartment when you cancel the lease.
				<<act 'Return'>>
					<<gt 'agentned' 'start'>>
				<</act>>
				<<actCLA 'Cancel it'>>
					<<gs 'homes_properties' 'cancel_rent' 'old_town_apartment'>> <<gt 'agentned' 'start'>>
				<</actCLA>>
			<</actCLA>>
		<</if>>
		<<set $i += 1>>
		<<if $i < $count>>
			<<warn 'JUMP COMMAND ENCOUNTERED: jump listing_rented_properties_loop'>>

		<</if>>
	<</if>>
	<!-- !! Get a list of the properties and their attributes that the player rented:-->
	<!-- !! $property_code[], $property_name[], $property_display[], $property_status_display[], $property_type[]-->
	<!-- !! property_construction_status, property_is_renovated[], property_sales_price[], property_renovation_value[]-->
	<<gs 'homes_properties' 'get_owned_properties' 'home'>>
	<<set $count = ARRSIZE('$property_name')>>
	<<if getvar("$count") > 0>>
		<h4>You own the following properties</h4>
		<<set $i = 0>>
		<<warn 'JUMP MARKER ENCOUNTERED: :listing_owned_properties_loop'>>
		$property_status_display[$i]
		<<set $i += 1>>
		<<if $i < $count>>
			<<warn 'JUMP COMMAND ENCOUNTERED: jump listing_owned_properties_loop'>>

		<</if>>
		We are at your service if you decide to <<link "sell">><<gt 'agentned' 'sell'>><</link>>.
	<</if>>
	<<gs 'homes_properties' 'clean_up_property_data'>>
	<<actCLA 'Leave'>>
		<<set $time.minutes += 5>> <<gt 'city_center'>>
	<</actCLA>>
<</if>>
<<if $location_var[$here][0] == 'buy'>>
	<<set $loc = 'agentned'>>
	<<set $loc_arg = $location_var[$here][0]>>
	<<set $location_type = 'indoors'>>
	<<set $menu_loc = 'agentned'>>
	<<set $menu_arg = 'buy'>>
	<<set $menu_off = 0>>
	<<gs 'housing' 'sale'>>
	<<gs 'homes_properties' 'clean_up_property_data'>>
	<h2>Real Estate Agency</h2>
	<<image "locations/city/citycenter/realestate/agenstvo.jpg">>
	<h4> The purchase of any properties requires a bank account. The Agency is not conducting business in cash in compliance with the Anti-Money Laundering Regulations</h4>
	<<set $time.minutes += 5>>
	<<act 'Return'>>
		<<gt 'agentned' 'start'>>
	<</act>>
	<!-- !! "Returns":-->
	<!-- !! $property_code[], $property_name[], $property_display[], $property_agency_name[],-->
	<!-- !! property_construction_status,property_is_renovated[], property_sales_price[],-->
	<!-- !! property_type[]-->
	<<gs 'homes_properties' 'get_properties_for_sale'>>
	<<set $count = ARRSIZE('$property_name')>>
	<<if getvar("$count") > 0>>
		<<set $i = 0>>
		<h4>We have the following properties for sales</h4>
		<<warn 'JUMP MARKER ENCOUNTERED: :listing_properties_for_sale_loop'>>
		<<if getvar("$property_is_rented["+$i+"]") != 0>>
			<p>You could buy the $property_display[$i] you're currently renting, for setup.func('agentned', 'format_price_string', property_sales_price[$i]) <b>₽</b>.</p>
		<<else>>
			<p>A(n) $property_display[$i] is available for sale for setup.func('agentned', 'format_price_string', property_sales_price[$i]) <b>₽</b>.</p>
		<</if>>
		<<if $finances.bankAvailable >= $property_sales_price[$i]>>
			<<if $property_code[$i] == 'city_apartment'>>
				<<actCLA 'Buy the $property_display['+'+$i]+'+''>>
	<<gs 'agentned' 'buy_property' 'city_apartment'>>
<</actCLA>>

			<</if>>
			<<if $property_code[$i] == 'village_cottage'>>
				<<actCLA 'Buy the $property_display['+'+$i]+'+''>>
	<<gs 'agentned' 'buy_property' 'village_cottage'>>
<</actCLA>>

			<</if>>
			<<if $property_code[$i] == 'matryona_mansion'>>
				<<actCLA 'Buy the $property_display['+'+$i]+'+''>>
	<<gs 'agentned' 'buy_property' 'matryona_mansion'>>
<</actCLA>>

			<</if>>
			<<if $property_code[$i] == 'city_house'>>
				<<actCLA 'Buy the $property_display['+'+$i]+'+''>>
	<<gs 'agentned' 'buy_property' 'city_house'>>
<</actCLA>>

			<</if>>
		<</if>>
		<<set $i += 1>>
		<<if $i < $count>>
			<<warn 'JUMP COMMAND ENCOUNTERED: jump listing_properties_for_sale_loop'>>

		<</if>>
	<<else>>
		We currently have no properties listed for sale.
	<</if>>
	<<gs 'homes_properties' 'clean_up_property_data'>>
<</if>>
<<if $location_var[$here][0] == 'buy_property'>>
	<<set $menu_off = 1>>
	<<gs 'homes_properties' 'get_property_sales_info' $location_var[$here][1]>>
	<<set $time.minutes += 30>>
	<<set $finances.bank -= $property_sales_price>>
	<<gs 'homes_properties' 'buy_property' $location_var[$here][1] $property_sales_price>>
	<<set $set_homeyn = input("Would you like to set this as your new home? ($yes / $no)")>>
	<<if $set_homeyn == 'yes'>>
		<<gs 'homes_properties' 'set_home' $location_var[$here][1]>>

	<</if>>
	<<set $set_homeyn to null>>
	<!-- !!TODO: this etoexhib will need some rethinking I get what it means by now, but some better name would help a lot.-->
	<!-- !!NOTE: It means how "famous" Sveta is for being an exhibitionist.-->
	<<if $location_var[$here][1] == 'village_cottage'>>
		<<set $etoexhib = 0>>

	<</if>>
	<h2>Real Estate Agency</h2>
	<<image "locations/city/citycenter/realestate/agenstvo_paperwork.jpg">>
	<p>You spend half an hour filling in the paperwork to buy the $property_display. setup.func('agentned', 'format_price_string', property_sales_price)<b>₽</b> has been removed from your bank account.</p>
	<<act 'Return'>>
		<<gt 'agentned' 'start'>>
	<</act>>
<</if>>
<!-- !! NOTE: When a property is sold, it can be bought back. To avoid a guaranteed income from the-->
<!-- !!       "I buy property for X, renovate it, sell it for X+Y, then buy it for X, then repeat" loop,-->
<!-- !!       the sales price of the property is updated with the price that it was sold for.-->
<<if $location_var[$here][0] == 'sell'>>
	<<set $loc = 'agentned'>>
	<<set $loc_arg = $location_var[$here][0]>>
	<<set $location_type = 'indoors'>>
	<<set $menu_loc = 'agentned'>>
	<<set $menu_arg = 'sell'>>
	<<set $menu_off = 0>>
	<<gs 'homes_properties' 'clean_up_property_data'>>
	<h2>Real Estate Agency</h2>
	<<image "locations/city/citycenter/realestate/agenstvo.jpg">>
	<h4>Any purchase or sale of a property requires a bank account. The Agency is not conducting business in cash in compliance with the Anti-Money Laundering Regulations</h4>
	<<actCLA 'Return'>>
		<<gs 'homes_properties' 'clean_up_property_data'>> <<gt 'agentned' 'start'>>
	<</actCLA>>
	<<if $finances.hasBankAccount == 1>>
		<!-- !! Get a list of the properties and their attributes that the player rented:-->
		<!-- !! $property_code[], $property_name[], $property_display[], $property_status_display[], $property_type[]-->
		<!-- !! property_construction_status, property_is_renovated[], property_sales_price[], property_renovation_value[]-->
		<<gs 'homes_properties' 'get_owned_properties' 'home'>>
		<<set $count = ARRSIZE('$property_name')>>
		<<if getvar("$count") > 0>>
			<h4>Available offers for your properties</h4>
			<<set $i = 0>>
			<<warn 'JUMP MARKER ENCOUNTERED: :listing_offers_on_owned_properties_loop'>>
			<<if $property_code[$i] != 'matryona_mansion' or ($property_code[$i] == 'matryona_mansion' and getvar("$property_construction_status["+$i+"]") == 0)>>
				<!-- !! NOTE: Offer: (last sales price + rand(-10%, +10%)) + (renovation value + rand(0%,+10%)-->
				<!-- !! 		 No need to check what has been renovated, the only thing that matters is the total value of the renovation-->
				<!-- !! 		 If Sveta sells, this will be stored as the new sales price of the property-->
				<<set $offer = $property_sales_price + $property_renovation_value + (property_sales_price * rand(-10,10)) / 100 + (property_renovation_value * rand(0,10)) / 100>>
				<p>We have found a buyer for your $property_display[$i]. They will offer setup.func('agentned', 'format_price_string', offer)<b>₽</b>, minus 5% for fees and taxes to the value of setup.func('agentned', 'format_price_string', ( (offer*5)/100) ), bringing the total to setup.func('agentned', 'format_price_string', ( (offer*95)/100 ) )</p>
				<<if $property_code[$i] == 'city_apartment'>>
					<<actCLA 'Sell the $property_display['+'+$i]+'+''>>
	<<gs 'agentned' 'finalise_sale' 'city_apartment'>>
<</actCLA>>

				<</if>>
				<<if $property_code[$i] == 'village_cottage'>>
					<<actCLA 'Sell the $property_display['+'+$i]+'+''>>
	<<gs 'agentned' 'finalise_sale' 'village_cottage'>>
<</actCLA>>

				<</if>>
				<<if $property_code[$i] == 'matryona_mansion'>>
					<<actCLA 'Sell the $property_display['+'+$i]+'+''>>
	<<gs 'agentned' 'finalise_sale' 'matryona_mansion'>>
<</actCLA>>

				<</if>>
				<<if $property_code[$i] == 'city_house'>>
					<<actCLA 'Sell the $property_display['+'+$i]+'+''>>
	<<gs 'agentned' 'finalise_sale' 'city_house'>>
<</actCLA>>

				<</if>>
			<</if>>
			<<set $i += 1>>
			<<if $i < $count>>
				<<warn 'JUMP COMMAND ENCOUNTERED: jump listing_offers_on_owned_properties_loop'>>

			<</if>>
		<</if>>
		<<gs 'homes_properties' 'clean_up_property_data'>>
		<<actCLA 'Leave'>>
			<<set $time.minutes += 5>> <<gt 'city_center'>>
		<</actCLA>>
		<!-- !! NOTE: Keeping this here for future renovation related reference.-->
		<!-- !!{
		if bankAccount = 1:
		if rembedr = 1 and remsitr = 1 and remkorr = 1 and remvanr = 1 and remkuhr = 1:
		!Renovated city residential apartment
		offer1 = ((800000 + 250000) + rand(-100000, 100000))
		else
		offer1 = (800000 + rand(-100000, 100000))
		end
		if setup.func('homes_properties', 'property_renovated', 'village_cottage') = 1:
		!Renovated communal cottage
		offer2 = ((prop_price['village_cottage'] + 200000) + rand(-10000, 10000))
		else
		!Communal cottage
		offer2 = (prop_price['village_cottage'] + rand(-5000, 5000))
		end
		} -->
	<<else>>
		<b>You need to open a bank account to sell your property</b>
	<</if>>
<</if>>
<<if $location_var[$here][0] == 'finalise_sale'>>
	 	<<set $menu_off = 1>>
	<<gs 'homes_properties' 'get_property_sales_info' $location_var[$here][1]>>
	<h2>Real Estate Agency</h2>
	<<image "locations/city/citycenter/realestate/agenstvo_paperwork.jpg">>
	<<set $time.minutes += 30>>
	<p>You spend thirty minutes filling out the paperwork for the sale of your $property_display. setup.func('agentned', 'format_price_string', ( (offer*95)/100) )<b>₽</b> has been paid into your bank account.</p>
	<<gs 'homes_properties' 'sell_property' $location_var[$here][1] $offer>>
	<<set $finances.bank += ($offer * 95) / 100>>
	delact 'Sell the $property_display'
<</if>>
<<if $location_var[$here][0] == 'rent'>>
	<<set $loc = 'agentned'>>
	<<set $loc_arg = $location_var[$here][0]>>
	<<set $location_type = 'indoors'>>
	<<set $menu_loc = 'agentned'>>
	<<set $menu_arg = 'rent'>>
	<<set $menu_off = 0>>
	<h2>Real Estate Agency</h2>
	<<image "locations/city/citycenter/realestate/agenstvo.jpg">>
	<<set $time.minutes += 5>>
	<<act 'Return'>>
		  <<gt 'agentned' 'start'>>
	<</act>>
	<<gs 'homes_properties' 'get_properties_for_rent' 'home'>>
	<<set $count = ARRSIZE('property_name')>>
	<<if getvar("$count") > 0>>
		<<set $i = 0>>
		<h4>Properties currently available for rent</h4>
		<<warn 'JUMP MARKER ENCOUNTERED: :listing_properties_for_rent_loop'>>
		<p>We have a(n) $property_display[$i] avaible for a monthly rent of setup.func('agentned', 'format_price_string', property_rent[$i])<b>₽</b>.</p>
		<<setinit $time.monthly_rent[$property_code[$i]] = $property_rent[$i]>>
		<<if $property_code[$i] == 'city_apartment'>>
			<<actCLA 'View the $property_display['+'+$i]+'+' details'>>
	<<gt 'agentned' 'view_property_details' 'city_apartment' $time.monthly_rent['city_apartment']>>
<</actCLA>>

		<</if>>
		<<if $property_code[$i] == 'old_town_apartment'>>
			<<actCLA 'View the $property_display['+'+$i]+'+' details'>>
	<<gt 'agentned' 'view_property_details' 'old_town_apartment' $time.monthly_rent['old_town_apartment']>>
<</actCLA>>

		<</if>>
		<<set $i += 1>>
		<<if $i < $count>>
			<<warn 'JUMP COMMAND ENCOUNTERED: jump listing_properties_for_rent_loop'>>

		<</if>>
	<<else>>
		We currently have no properties listed for rent.
	<</if>>
	<<gs 'homes_properties' 'clean_up_property_data'>>
<</if>>
<<if $location_var[$here][0] == 'view_property_details'>>
	<<set $menu_off = 1>>
	<h2>Real Estate Agency</h2>
	<<image "locations/city/citycenter/realestate/agenstvo.jpg">>
	<p>func('agentned', 'get_rent_detail_dialogue', $larg(1) ) The receptionist says as he starts pulling out the paperwork, "Rent is setup.func('agentned', 'format_price_string', ARGS[2] )<b>₽</b> and leases have to be renewed every 30 days. Payment will be automatically deducted from your account or you can come into the office to pay. Last, but not least, you must make pay the first month when you sign for the lease."</p>
	<p><br>He pulls out a pen and slides the paperwork onto the counter. "Interested? You can move in right away," he says calmly.</p>
	<<if $finances.cash >= $larg(2) or $finances.bankAvailable >= $larg(2)>>
		<<actCLA 'Agree and pay'>>
			<<set $time.minutes += 30>>
			<<if $finances.cash >= $larg(2)>>
				<<set $finances.cash -= $larg(2)>>
			<<else>>
				<<set $finances.bank -= $larg(2)>>
			<</if>>
			<<gs 'homes_properties' 'rent_property' $location_var[$here][1]>>
			<<if setup.func( 'homes_properties', 'get_accessible_property_count', 'home') == 1>>
				<<gs 'homes_properties' 'set_home' $location_var[$here][1]>>
			<<else>>
				<<set $set_homeyn = input("Would you like to set this as your new home? ($yes / $no)")>>
				<<if $set_homeyn == 'yes'>>
					<<gs 'homes_properties' 'set_home' $location_var[$here][1]>>

				<</if>>
				<<set $set_homeyn to null>>
			<</if>>
			<h2>Real Estate Agency</h2>
			<<image "locations/city/citycenter/realestate/agenstvo_paperwork.jpg">>
			You take the pen then start filling out the paperwork. After writing for half an hour, you hand over the money and receive the keys to your new apartment.
			<<act 'Return'>>
				<<gt 'agentned' 'start'>>
			<</act>>
		<</actCLA>>
	<<else>>
		You do not have enough money with you or in your bank account to pay the rent.
	<</if>>
	<<actCLA 'Decline'>>
		<<set $time.minutes += 5>>
		<h2>Real Estate Agency</h2>
		<<image "locations/city/citycenter/realestate/agenstvo.jpg">>
		You shake your head, "Actually, I need more time to think about this."
		<br>The receptionist seems a bit miffed, but says nothing as he takes back the paperwork and stuffs it back into his desk drawer.
		<<act 'Return'>>
			<<gt 'agentned' 'start'>>
		<</act>>
	<</actCLA>>
<</if>>
<!-- !! $larg(1) - the code of the property.-->
<<if $location_var[$here][0] == 'get_rent_detail_dialogue'>>
	<<if $location_var[$here][1] == 'old_town_apartment'>>
		<<set $result = '"We have a small apartment available right now that is in Pushkin’s city center. It’s a little bit pricey, but it’s been recently renovated to be more modern. It looks quite nice, so you won’t find a place like that outside of Pushkin."'>>
	<<elseif $location_var[$here][1] == 'city_apartment'>>
		<<set $result = '"We have a flat available right now in the St. Petersburg residential area."'>>
	<<else>>
		<<gs 'agentned' 'get_rent_detail_dialogue_hook' $location_var[$here][1]>>
		<<set $result = $agency_rental_dialogue>>
		<<set $agency_rental_dialogue to null>>
	<</if>>
<</if>>
<!-- !! $larg(1) - the code of the property.-->
<<if $location_var[$here][0] == 'get_rent_detail_dialogue_hook'>>
	<!-- !! In a mod just redirect this call and set the value of the variable below to the text-->
	<!-- !! that should be used for the property by the agency.-->
	<<set $agency_rental_dialogue = ''>>
<</if>>
<!-- !! Call: `setup.func('agentned', 'format_price_string', ARGS[1])-->
<!-- !! ARGS[1] - the price (as a number)-->
<<if $location_var[$here][0] == 'format_price_string'>>
	<<set $worknum = STR(ARGS[1])>>
	<<set $worknumlength = LEN($worknum)>>
	<<set $pos1 = 1>>
	<<warn 'JUMP MARKER ENCOUNTERED: :format_price_string_loop'>>
	<<set $split = mid($worknum, pos1, 1)>>
	<<if ($worknumlength - 1) / 3>>
		<<set $result += $split + ','>>
	<<else>>
		<<set $result += $split>>
	<</if>>
	<<set $worknumlength -= 1>>
	<<set $pos1 += 1>>
	<<if $pos2 <= $worknumlength>>
		<<warn 'JUMP COMMAND ENCOUNTERED: jump format_price_string_loop'>>

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