:: homes_properties
<<info 'homes_properties is deprecated'>>

<<set $here = 'homes_properties'>>
<<set $ARGS = $location_var[$here]>>

<<if !$accessible_property>><<set $accessible_property = {}>><</if>>
<<if !$accessible_property_str >><<set $accessible_property_str  = {}>><</if>>
<<if !$property>><<set $property = {}>><</if>>

<<if ARRSIZE('home_name') < 4>>
	<<gs 'homes_properties_attr' ''>>
<</if>>
<!-- !! NOTE: The code will set the value to -1 if now property of correct type is found.-->
<!-- !!       The reason for this is to make sure that it will not run more than once because there are no properties of that type - like business properties right now -,-->
<!-- !!  	 but to also make it sure that if we add one or more, either in the main game, or via some mod, we won't have to worry about this, as it will calculate correctly.-->
<<if (getvar("$accessible_property['available_for_rent_home_count']") == 0 or $accessible_property['available_for_rent_business_count']) and $location_var[$here][0] != 'get_rentable_property_count'>>
	<<gs 'homes_properties' 'get_rentable_property_count'>>
<</if>>
<!-- !!------------------------------------------------------------------------------------------------------->
<!-- !!-->
<!-- !!   General calls-->
<!-- !!-->
<!-- !!------------------------------------------------------------------------------------------------------->
<!-- !! Call: `gs 'homes_properties', 'calculate_available_for_rent_property_count'`-->
<!-- !! This calculate the value of accessible_property['available_for_rent_home_count'] and accessible_property['available_for_rent_business_count']-->
<!-- !! Right now it is called once when the first call to this location finds that the value for these are 0.-->
<!-- !! However, I added it as a named thing in case a mod adds new properties, especially business type properties, in which the mod should call this-->
<!-- !! to recalculate the values to include the newly added properties.-->
<!-- !!-->
<!-- !! NOTE: The code will set the value to -1 if now property of correct type is found.-->
<!-- !!       The reason for this is to make sure that it will not run more than once because there are no properties of that type - like business properties right now -,-->
<!-- !!  	 but to also make it sure that if we add one or more, either in the main game, or via some mod, we won't have to worry about this, as it will calculate correctly.-->
<!-- !!-->
<!-- !! ARGS[1] - property type filter: 'home', 'business', 'all' or '' or missing-->
<<if $location_var[$here][0] == 'calculate_rentable_property_count'>>
	<<set $count = ARRSIZE('$home_name')>>
	<<for $i = 0; $i < $count; $i += 1>>
		<<gs 'homes_properties_attr' 'get_property_attr' $home_name[$i]>>
		<<if ($ARGS[1] != 'home' and INSTR($property['type'], 'residence') == 0) and $property['rental']>>
			<<setinit $accessible_property['rentable_business_count'] += 1>>
		<<elseif ($ARGS[1] != 'business' and INSTR($property['type'], 'business') == 0) and $property['rental']>>
			<<setinit $accessible_property['rentable_rent_home_count'] += 1>>
		<</if>>
	<</for>>
	<<if getvar("$accessible_property['rentable_business_count']") == 0>>
		<<setinit $accessible_property['rentable_business_count'] = -1>>

	<</if>>
	<<if getvar("$accessible_property['rentable_home_count']") == 0>>
		<<setinit $accessible_property['rentable_home_count'] = -1>>

	<</if>>
	<<setinit $accessible_property['available_for_rent_home_count'] = $accessible_property['rentable_home_count']>>
	<<setinit $accessible_property['available_for_rent_business_count'] = $accessible_property['rentable_business_count']>>
<</if>>
<!-- !! Set the current home for Sveta based on either the property code or the id - for backward compatibility or some mods-->
<!-- !! $ARGS[1] - a string to identify the property.-->
<!-- !!			  Possible values:-->
<!-- !!			  A property code - 'city_apartment', 'village_cottage', etc.-->
<!-- !!			  A location name - $loc passed-->
<!-- !! 			  An empty string - in this case ARGS[2] is mandatory-->
<!-- !!			  A number as str - really should remove this-->
<!-- !!-->
<<if $location_var[$here][0] == 'set_home'>>
	<<set $housing.home = $location_var[$here][1]>>
	<!--<<set $homepropcode = iif(!$ARGS[1], $home_name[$loc], $home_name[$ARGS[1]])>>
	<<if $homepropcode != ''>>
		<<set $home to null>>
		<<gs 'homes_properties_attr' 'get_property_attr' $homepropcode>>
		<<if INSTR($property['type'], 'residence') > 0>>
			<<set $home = $property>>
			<<setinit $housing.home = $property['code']>>
			<<if $accessible_property[$housing.home] == 0>>
				<<gs 'homes_properties' 'set_access' $housing.home 1>>

			<</if>>
			<<set $property to null>>
		<</if>>
	<</if>>-->
<</if>>
<!-- !! Call: `gs 'homes_properties', 'set_access', $ARGS[1], ARGS[2], ARGS[3]. ARGS[4]-->
<!-- !!-->
<!-- !! $ARGS[1]: the location for which the access is set-->
<!-- !!			Accepted values-->
<!-- !!			- property code   -> 'city_apartment', 'homeParents'-->
<!-- !!			- a location      ->  'bedrPar', 'koo2x' - A value that can shop up in $loc-->
<!-- !!			- empty strying   ->  '' - will work as if a location was passed, but will use the actual value of $loc-->
<!-- !!			- A number as str -> '1', '2' - this should be the id of the property-->
<!-- !!			  					NOTE: only added in case someone really want to use the old ids-->
<!-- !! ARGS[2]: ownership type-->
<!-- !!			0: no acces  -> 'no access'-->
<!-- !!			1: not owned but can live her - a rented property or living at some else''s place-->
<!-- !!			2: owned     -> 'owned'-->
<!-- !!			3: owned and rented out -> 'tenants'-->
<!-- !! ARGS[3]: construction status - optional-->
<!-- !!			0: land only-->
<!-- !!			1: foundation, frames built, utilities are connected-->
<!-- !!			2: fully built-->
<!-- !! ARGS[4]:renovation status - optional-->
<!-- !!			0: not renovated-->
<!-- !!			1: fully renovated-->
<<if $location_var[$here][0] == 'set_access'>>
	<<set $propcode = iif(!$ARGS[1], $home_name[$loc], $home_name[$ARGS[1]])>>
	<<set $orig_status_code = $accessible_property[$propcode]>>
	<<set $new_status_code = $ARGS[2]>>
	<<if $orig_status_code != $new_status_code>>
		<<if !$accessible_property_str[$propcode] or !$accessible_property_str[$propcode+"-display"] or !$accessible_property_str[$propcode+"-name"]>>
			<<if $property['code'] != $propcode>>
				<<gs 'homes_properties_attr' 'get_property_attr' $propcode>>
			<<else>>
				<<set $nokill = 1>>
			<</if>>
			<<if $location_var[$here][2] == 1 and getvar("$property['rental']") == 0>>
				<<set $new_status_code = 4>>

			<</if>>
			<<setinit $accessible_property[$propcode] = $new_status_code>>
			<<setinit $accessible_property_str[$propcode] = $propcode>>
	 			<<setinit $accessible_property_str[$propcode + '-name'] = $property['name']>>
	 			<<setinit $accessible_property_str[$propcode + '-type'] = $property['type']>>
			<<if $property['construction_needed'] == 1>>
 				<<setinit $accessible_property[$propcode + '-construction-status'] = $ARGS[3]>>
 				<<setinit $accessible_property_str[$propcode + '-display'] = $property['display_' + $location_var[$here][3]]>>
			<<else>>
				<<setinit $accessible_property[$propcode + '-construction-status'] = 2>>
				<<setinit $accessible_property_str[$propcode + '-display'] = $property['display']>>
			<</if>>
			<<if INSTR($property['type'], 'residence') > 0>>
				<<setinit $accessible_property[$propcode + '-is-home'] = 1>>
			<</if>>
 			<<setinit $accessible_property[$propcode + '-rental'] = $property['rental']>>
			<<setinit $accessible_property[$propcode + '-renovated'] = $ARGS[4]>>
			<<setinit $accessible_property[$propcode + '-sales-price'] = $property['price']>>
 			<<setinit $accessible_property[$propcode + '-rent'] = $property['rent']>>
		<</if>>
		<<if getvar("$accessible_property["+$propcode+"]") == 0>>
			<!-- !! If this was the current home then killing it-->
			<<if getvar("$housing.home") == $propcode>>
				<<set $home to null>>

			<</if>>
			<!-- !! Updating home counts-->
			<!-- !! NOTE: Valid transitions: 1 -> 0, 2 -> 0, 4 -> 0-->
 			<<if $accessible_property[$propcode + '-is-home'] == 1>> -->
				<<if $orig_status_code == 1>>
					<<setinit $accessible_property['rental_home_count'] -= 1>>
					<<setinit $accessible_property['available_for_rent_home_count'] += 1>>
				<</if>>
				<<if getvar("$orig_status_code") == 2>>
					<<setinit $accessible_property['owned_home_count'] -= 1>>

				<</if>>
				<<if $accessible_property[$propcode + '-construction-status'] == 2>>
					<<setinit $accessible_property['furnishable_home_count'] -= 1>>

				<</if>>
				<<setinit $accessible_property['accessible_home_count'] -= 1>>
			<</if>>
			<<if getvar("$accessible_property['accessible_home_count']") == 1>>
				<<gs 'homes_properties' 'get_accessible_properties' 'home'>>
				<<if $accessible_property[$ARGS[1] + '-is-home'] == 1>>
					<<gs 'homes_properties' 'set_home' $property_code>>

				<</if>>
				<<gs 'homes_properties' 'clean_up_property_data'>>
			<</if>>
			<!-- !! Property is rented-->
		<<elseif getvar("$accessible_property["+$propcode+"]") == 1>>
			<!-- !! Updating home counts-->
			<!-- !! NOTE: Only valid transition is 0 -> 1-->
 			<<if $accessible_property[$propcode + '-is-home'] == 1>>
				<<setinit $accessible_property['rental_home_count'] += 1>>
				<<setinit $accessible_property['accessible_home_count'] += 1>>
				<<setinit $accessible_property['available_for_rent_home_count'] -= 1>>
				<<if $accessible_property[$propcode + '-construction-status'] == 2>>
					<<setinit $accessible_property['furnishable_home_count'] += 1>>

				<</if>>
			<</if>>
			<!-- !! Property is owned-->
		<<elseif getvar("$accessible_property["+$propcode+"]") == 2>>
			<!-- !! Updating home counts-->
			<!-- !! NOTE: Valid transitions: 0 -> 2, 1 -> 2, 3-> 2-->
			<<if $accessible_property[$propcode + '-is-home'] == 1>>
				<<if getvar("$orig_status_code") == 0>>
					<<setinit $accessible_property['accessible_home_count'] += 1>>
				<<elseif getvar("$orig_status_code") == 1>>
					<<setinit $accessible_property['rental_home_count'] -= 1>>
					<<setinit $accessible_property['available_for_rent_home_count'] += 1>>
				<<elseif getvar("$orig_status_code") == 3>>
					<<setinit $accessible_property['tenant_home_count'] -= 1>>
 					<<setinit $accessible_property[$propcode + '-tenant-day'] = -1>>
					<<setinit $accessible_property[$propcode + '-tenant-month'] = -1>>
					<<if $accessible_property[$propcode + '-construction-status'] == 2>>
						<<setinit $accessible_property['furnishable_home_count'] += 1>>

					<</if>>
				<</if>>
				<<if $accessible_property[$propcode + '-construction-status'] == 2 and $orig_status_code != 1>>
					<<setinit $accessible_property['furnishable_home_count'] += 1>>

				<</if>>
				<<setinit $accessible_property['owned_home_count'] += 1>>
			<</if>>
			<!-- !! Property has tenants-->
		<<elseif getvar("$accessible_property["+$propcode+"]") == 3>>
			<!-- !! Updating home counts-->
			<!-- !! NOTE: Valid transitions: 2 -> 3-->
			<<if $accessible_property[$propcode + '-is-home'] == 1>>
				<<if $housing.home == $propcode>>
					<<set $home to null>>

				<</if>>
				<<setinit $accessible_property['tenant_home_count'] += 1>>
				<<setinit $accessible_property['owned_home_count'] -= 1>>
				<<setinit $accessible_property['accessible_home_count'] -= 1>>
				<<if $accessible_property[$propcode + '-construction-status'] == 2>>
					<<setinit $accessible_property['furnishable_home_count'] -= 1>>

				<</if>>
			<</if>>
			<!-- !! Property is just accessible-->
		<<elseif getvar("$accessible_property["+$propcode+"]") == 4>>
			<!-- !! Updating home counts-->
			<!-- !! NOTE: Valid transitions: 0 -> 4-->
			<<if $accessible_property[$propcode + '-is-home'] == 1>>
				<<setinit $accessible_property['accessible_home_count'] += 1>>
			<</if>>
		<</if>>
	<</if>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'can_live_here', $ARGS[1])`-->
<!-- !! Return -1 if the location/property is a place where Sveta can live, whether he owns or rents the place,-->
<!-- !! she is just allowed to live there: university dorm, parents home, the Meynold Household, etc.-->
<!-- !!-->
<!-- !! $ARGS[1]: the location for which the access is set-->
<!-- !!			Accepted values-->
<!-- !!			- property code   -> 'city_apartment', 'homeParents'-->
<!-- !!			- a location      ->  'bedrPar', 'koo2x' - A value that can shop up in $loc-->
<!-- !!			- empty strying   ->  '' - will work as if a location was passed, but will use the actual value of $loc-->
<!-- !!			- A number as str -> '1', '2' - this should be the id of the property-->
<!-- !!			  					NOTE: only added in case someone really want to use the old ids-->
<<if $location_var[$here][0] == 'can_live_here'>>
	<<set $canlivecode = iif(!$ARGS[1], $home_name[$loc], $home_name[$ARGS[1]])>>
	<<set $result = (accessible_property[$canlivecode] > 0 and accessible_property[$canlivecode] ! 3 and setup.func('homes_properties','get_property_construction_status' , $canlivecode) == 2)>>
	<<set $canlivecode to null>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'is_current_home', $ARGS[1])`-->
<!-- !! Returns 0 if the location/property is not the current home, otherwise -1.-->
<!-- !!-->
<!-- !! $ARGS[1]: the location for which the access is set-->
<!-- !!			Accepted values-->
<!-- !!			- property code   -> 'city_apartment', 'homeParents'-->
<!-- !!			- a location      ->  'bedrPar', 'koo2x' - A value that can shop up in $loc-->
<!-- !!			- empty strying   ->  '' - will work as if a location was passed, but will use the actual value of $loc-->
<!-- !!			- A number as str -> '1', '2' - this should be the id of the property-->
<!-- !!			  					NOTE: only added in case someone really want to use the old ids-->
<<if $location_var[$here][0] == 'is_current_home'>>
	<<set $currenthomecode = iif(!$ARGS[1], $home_name[$loc], $home_name[$ARGS[1]])>>
	<<set $result = ($home["current"] == $currenthomecode)>>
	<<set $currenthomecode to null>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'is_at_a_home', $ARGS[1])`-->
<!-- !! Tells if the location passed in $ARGS[1] or if empty the $loc is a home or not.-->
<!-- !! If true then returns -1, if false 0.-->
<!-- !!-->
<!-- !! $ARGS[1]: the location for which the access is set-->
<!-- !!			Accepted values-->
<!-- !!			- property code   -> 'city_apartment', 'homeParents'-->
<!-- !!			- a location      ->  'bedrPar', 'koo2x' - A value that can shop up in $loc-->
<!-- !!			- empty strying   ->  '' - will work as if a location was passed, but will use the actual value of $loc-->
<!-- !!			- A number as str -> '1', '2' - this should be the id of the property-->
<!-- !!			  					NOTE: only added in case someone really want to use the old ids-->
<<if $location_var[$here][0] == 'is_at_a_home'>>
	<<set $isathomecode = <<run State.setVar('$'+$currentpursetype + '_purses['+$currentpursenumber+']',1)>>, $home_name[$loc], $home_name[$ARGS[1]])>>
	<<set $result = $accessible_property[$isathomecode+'-is-home'] == 1>>
	<<set $isathomecode to null>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'is_property_of_status', $ARGS[1])`-->
<!-- !! Tells if the location passed in $ARGS[1] or if empty the $loc is of the  queried status.-->
<!-- !! If true then returns -1, if false 0.-->
<!-- !!-->
<!-- !! $ARGS[1]: the status that is checked-->
<!-- !!			 Accepted values-->
<!-- !!			 'rented' -> is the property rented?-->
<!-- !!			 'owned'  -> is the property is owned (bought by Sveta) ?-->
<!-- !!			 'tenants' -> are there tenants in the property?-->
<!-- !!			 'purchased' -> both 'owned' and 'tenants'-->
<!-- !!			 'blocked' -> is the property blocked?-->
<!-- !!			 'hasaccess' -> can Sveta use the property (without owning or renting it)?-->
<!-- !!-->
<!-- !! $ARGS[2]: the location for which the access is set-->
<!-- !!			Accepted values-->
<!-- !!			- property code   -> 'city_apartment', 'homeParents'-->
<!-- !!			- a location      ->  'bedrPar', 'koo2x' - A value that can shop up in $loc-->
<!-- !!			- empty strying   ->  '' - will work as if a location was passed, but will use the actual value of $loc-->
<!-- !!			- A number as str -> '1', '2' - this should be the id of the property-->
<!-- !!			  					NOTE: only added in case someone really want to use the old ids-->
<<if $location_var[$here][0] == 'is_property_of_status'>>
	<<set $propstatcode = iif(!$ARGS[2], $home_name[$loc], $home_name[$ARGS[2]])>>
	<<if $location_var[$here][1] == 'rented'>>
 		<<set $result = ($accessible_property[$propstatcode] == 1)>>
	<<elseif $location_var[$here][1] == 'owned'>>
		<<set $result = ($accessible_property[$propstatcode] == 2)>>
	<<elseif $location_var[$here][1] == 'tenants'>>
		<<set $result = ($accessible_property[$propstatcode] == 3)>>
	<<elseif $location_var[$here][1] == 'blocked'>>
		<<set $result = ($accessible_property[$propstatcode] == 0)>>
	<<elseif $location_var[$here][1] == 'hasacces'>>
		<<set $result = ($accessible_property[$propstatcode] == 4)>>
	<<elseif $location_var[$here][1] == 'purchased'>>
		<<set $result = ($accessible_property[$propstatcode] == 2 or $accessible_property[$propstatcode] == 3)>>
	<<else>>
		<<set $result = 0>>
	<</if>>
	<<set $propstatcode to null>>
<</if>>
<!-- !! Call `setup.func('homes_properties', 'get_property_code', $ARGS[1])-->
<!-- !! Returns-->
<!-- !!-->
<!-- !! $ARGS[1]: the location for which the access is set-->
<!-- !!			Accepted values-->
<!-- !!			- property code   -> 'city_apartment', 'homeParents'-->
<!-- !!			- a location      ->  'bedrPar', 'koo2x' - A value that can shop up in $loc-->
<!-- !!			- empty strying   ->  '' - will work as if a location was passed, but will use the actual value of $loc-->
<!-- !!			- A number as str -> '1', '2' - this should be the id of the property-->
<!-- !!			  					NOTE: only added in case someone really want to use the old ids-->
<<if $location_var[$here][0] == 'get_property_code'>>
	<<set $result = iif(!$ARGS[1], $home_name[$loc], $home_name[$ARGS[1]])>>
<</if>>
<!-- !!----------------------------------------------------------->
<!-- !!  Home and Property Counts - setup.func()-->
<!-- !!----------------------------------------------------------->
<!-- !! Call: `setup.func('homes_properties', 'get_rented_property_count', $ARGS[1])`-->
<!-- !! Returns the count of rented properties-->
<!-- !!-->
<!-- !! ARGS[1] - property type filter: 'home', 'business', 'all' or '' or missing-->
<<if $location_var[$here][0] == 'get_rented_property_count'>>
	<<if $location_var[$here][1] == 'home'>>
		<<set $result = $accessible_property['rental_home_count']>>
	<<elseif $location_var[$here][1] == 'business'>>
		<<set $result = $accessible_property['rental_business_count']>>
	<<elseif $location_var[$here][1] == 'all' or $location_var[$here][1] == ''>>
		<<set $result = $accessible_property['rental_home_count'] + accessible_property['rental_business_count']>>
	<</if>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'get_accessible_property_count', $ARGS[1])`-->
<!-- !! Returns the count of accessible properties-->
<!-- !!-->
<!-- !! ARGS[1] - property type filter: 'home', 'business', 'all' or '' or missing-->
<<if $location_var[$here][0] == 'get_accessible_property_count'>>
	<<if $location_var[$here][1] == 'home'>>
		<<set $result = $accessible_property['accessible_home_count']>>
	<<elseif $location_var[$here][1] == 'business'>>
		<<set $result = $accessible_property['accessible_business_count']>>
	<<elseif $location_var[$here][1] == 'all' or $location_var[$here][1] == ''>>
		<<set $result = $accessible_property['accessible_home_count'] + accessible_property['accessible_business_count']>>
	<</if>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'get_rentable_property_count', $ARGS[1])`-->
<!-- !! Returns the count of properties that can be rented (all properties with where property['rental'] = 1)-->
<!-- !!-->
<!-- !! ARGS[1] - property type filter: 'home', 'business', 'all' or '' or missing-->
<<if $location_var[$here][0] == 'get_rentable_property_count'>>
	<<if $location_var[$here][1] == 'home'>>
		<<set $result = $accessible_property['rentable_home_count']>>
	<<elseif $location_var[$here][1] == 'business'>>
		<<set $result = $accessible_property['rentable_business_count']>>
	<<elseif $location_var[$here][1] == 'all' or $location_var[$here][1] == ''>>
		<<set $result = $accessible_property['rentable_home_count'] + accessible_property['rentable_business_count']>>
	<</if>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'get_available_for_rent_property_count', $ARGS[1])`-->
<!-- !! Returns the number of properties that are avaiable for rent - rentable properties that are not rented.-->
<!-- !! ARGS[1] - property type filter: 'home', 'business', 'all' or '' or missing-->
<<if $location_var[$here][0] == 'get_available_for_rent_property_count'>>
	<<if $location_var[$here][1] == 'home'>>
		<<set $result = $accessible_property['available_for_rent_home_count']>>
	<<elseif $location_var[$here][1] == 'business'>>
		<<set $result = $accessible_property['available_for_rent_business_count']>>
	<<elseif $location_var[$here][1] == 'all' or $location_var[$here][1] == ''>>
		<<set $result = $accessible_property['available_for_rent_home_count'] + accessible_property['available_for_rent_business_count']>>
	<</if>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'furnishable_home_count', $ARGS[1])`-->
<!-- !! Returns the count of furnishable properties (for shops)-->
<!-- !!-->
<!-- !! ARGS[1] - property type filter: 'home', 'business', 'all' or '' or missing-->
<<if $location_var[$here][0] == 'get_furnishable_property_count'>>
	<<if $location_var[$here][1] == 'home'>>
		<<set $result = $accessible_property['furnishable_home_count']>>
	<<elseif $location_var[$here][1] == 'business'>>
		<<set $result = $accessible_property['furnishable_business_count']>>
	<<elseif $location_var[$here][1] == 'all' or $location_var[$here][1] == ''>>
		<<set $result = $accessible_property['furnishable_home_count'] + accessible_property['furnishable_business_count']>>
	<</if>>
<</if>>
<!-- !!----------------------------------------------------------->
<!-- !!  Get Properties and their values-->
<!-- !!----------------------------------------------------------->
<!-- !! Use it as `gs`, creates a set of arrays that contains the relevant info for-->
<!-- !! rented properties-->
<!-- !!-->
<!-- !! Returns: property_rent, property_days, $property_name, $property_display, $property_code-->
<!-- !! $ARGS[1] - the property_type: 'home' - homes, 'business' - business properties, 'all' or '' - both types-->
<!-- !!  ARGS[2] - optional, if value is 1 then only $property_code[] is created.-->
<<if $location_var[$here][0] == 'get_rented_properties'>>
	<<set $j = 0>>
	<<gs 'homes_properties' 'clean_up_property_data'>>
	<<set $count = ARRSIZE('accessible_property')>>
	<<for $i = 0; $i < $count; $i += 1>>
		<<set $getrentedpropcode = $accessible_property_str[$i]>>
		<<if $home_name[$getrentedpropcode] != '' and getvar("$accessible_property["+$i+"]") == 1>>
			<<if ($location_var[$here][1] != "home" and $accessible_property[$getrentedpropcode + '-is-home'] == 0) or ($location_var[$here][1] != "business" and $accessible_property[$getrentedpropcode + '-is-home'] == 1)>>
				<<setinit $property_code[$j] = $getrentedpropcode>>
				<<if $location_var[$here][2] == 0>>
					<<setinit $property_name[$j] = $accessible_property_str[$getrentedpropcode + '-name']>>
					<<setinit $property_display[$j] = $accessible_property_str[$getrentedpropcode + '-display']>>
					<<setinit $property_days[$j] = $accessible_property[$getrentedpropcode + 'days-left']>>
					<<setinit $property_rent[$j] = $accessible_property[$getrentedpropcode + '-rent']>>
				<</if>>
				<<set $j += 1>>
			<</if>>
		<</if>>
	<</for>>
<</if>>
<!-- !! Use it as `gs`, creates a set of arrays that contains the relevant info for-->
<!-- !! all owned (bought) properties.-->
<!-- !!-->
<!-- !! "Returns":-->
<!-- !! $property_code[], $property_name[], $property_display[], $property_status_display[], $property_type[]-->
<!-- !! property_status[], property_construction_status, property_is_renovated[], property_sales_price[],-->
<!-- !! property_renovation_value[]-->
<!-- !!-->
<!-- !! $ARGS[1] - the class of the property: 'home' - returns only homes; 'business' - returns only business properties;-->
<!-- !!										 'all' or '' (or $ARGS[1] not passed) - returns both types-->
<!-- !!			  IMPORTANT: If $ARGS[2] is passed, the $ARGS[1] will be ignored and will be treated as if it was 'all'/''.-->
<!-- !! $ARGS[2] - optional, a property code or a location. If $ARGS[2] passed, only one property will be checked and returned.-->
<!-- !!-->
<<if $location_var[$here][0] == 'get_owned_properties'>>
	<<set $j = 0>>
	<<gs 'homes_properties' 'clean_up_property_data'>>
	<<set $type = iif(!$ARGS[2], $ARGS[1], 'all')>>
	<<set $count = iif(!$ARGS[2], ARRSIZE('accessible_property'), 1)>>

	<<for $i = 0; $i < $count; $i += 1>>
		<!-- !!'<h3>Building Owned Properties List</h3>'-->
		<!-- !!'Count: <b><<count>></b>'-->
		<<set $getownedpropcode = iif( !$ARGS[2], $accessible_property_str[$i], $ARGS[2] )>>
		<!-- !!'  Index: <b><<i>></b> Code: <b><<$getownedpropcode>></b> Status: <b><<accessible_property[$i]>></b>'-->
		<<if $home_name[$getownedpropcode] != '' and (getvar("$accessible_property["+$getownedpropcode+"]") == 2 or getvar("$accessible_property["+$getownedpropcode+"]") == 3)>>
			<!-- !!'    $ARGS[1]: <b><<$ARGS[$i]>></b> Is home: <b><<accessible_property['''+$$getownedpropcode+'-is-home'']>></b>'-->
			<<if ($type != "home" and $accessible_property[$getownedpropcode + '-is-home'] == 0) or ($type != "business" and $accessible_property[$getownedpropcode + '-is-home'] == 1)>>
				<<setinit $property_code[$j] = $getownedpropcode>>
				<<setinit $property_name[$j] = $accessible_property_str[$getownedpropcode + '-name']>>
				<<if $property['construction_needed'] == 1>>
					<<setinit $property_display[$j] = iif(!$accessible_property_str[$getownedpropcode], $property['display_0'], $accessible_property_str[$getownedpropcode+'-display'])>>
				<<else>>
					<<setinit $property_display[$j] = iif(!$accessible_property_str[$getownedpropcode], $property['display'], $accessible_property_str[$getownedpropcode+'-display'])>>
				<</if>>
				<<setinit $property_type[$j] = $accessible_property_str[$getownedpropcode + '-type']>>
				<<if getvar("$accessible_property["+$getownedpropcode+"]") == 3>>
					<<setinit $property_status_display[$j] = 'A(n) $property_display[$j] which is currently occupied by your tenants'>>
				<<else>>
					<<setinit $property_status_display[$j] = 'A(n) $property_display[$j] ' + iif($accessible_property_str[$getownedpropcode] == $housing.home, 'where you currently live.', 'which is currently empty.')>>
				<</if>>
				<<setinit $property_status[$j] = $accessible_property[$getownedpropcode]>>
				<<setinit $property_construction_status[$j] = $accessible_property[$getownedpropcode + '-construction-status']>>
				<<setinit $property_is_renovated[$j] = $accessible_property[$getownedpropcode + '-renovated']>>
				<<setinit $property_sales_price[$j] = $accessible_property[$getownedpropcode + '-sales-price']>>
				<<setinit $property_renovation_value[$j] = $accessible_property[$getownedpropcode + '-renovation-value']>>
				<<set $j += 1>>
			<</if>>
		<</if>>
	<</for>>
<</if>>
<!-- !! Use it as `gs`, creates a set of arrays that contains the relevant info for-->
<!-- !! all accessible (rented, bought or just allowed to stay) properties.-->
<!-- !!-->
<!-- !! "Returns":-->
<!-- !! $property_code[], $property_name[], $property_display[], $property_status_display[], $property_type[]-->
<!-- !! property_status[], property_construction_status[], property_is_renovated[], property_renovation_value[]-->
<!-- !!-->
<!-- !! $ARGS[1] - the class of the property: 'home' - returns only homes; 'business' - returns only business properties; '' - returns both types-->
<<if $location_var[$here][0] == 'get_accessible_properties'>>

	<<set $j = 0>>
	<<gs 'homes_properties' 'clean_up_property_data'>>
	<<set $count = ARRSIZE('accessible_property')>>
	<<for $i = 0; $i < $count; $i += 1>>
		<<set $getaccessiblepropcode = $accessible_property_str[$i]>>
		<<if $home_name[$getaccessiblepropcode] != '' and getvar("$accessible_property["+$getaccessiblepropcode+"]") > 0>>
			<<if ($location_var[$here][1] != "home" and $accessible_property[$getaccessiblepropcode + '-is-home'] == 0) or ($location_var[$here][1] != "business" and $accessible_property[$getaccessiblepropcode + '-is-home'] == 1)>>
				<<setinit $property_code[$j] = $getaccessiblepropcode>>
				<<setinit $property_name[$j] = $accessible_property_str[$getaccessiblepropcode + '-name']>>'>>
				<<if $property['construction_needed'] == 1>>
					<<setinit $property_display[$j] = iif(!$accessible_property_str[$getaccessiblepropcode], $property['display_0'], $accessible_property_str[$getaccessiblepropcode+'-display'])>>
				<<else>>
					<<setinit $property_display[$j] = iif(!$accessible_property_str[$getaccessiblepropcode], $property['display'], $accessible_property_str[$getaccessiblepropcode+'-display'])>>
				<</if>>
				<<if getvar("$accessible_property["+$getaccessiblepropcode+"]") == 1>>
					<<setinit $property_status_display[$j] = 'You rent the $property_display[$j] '+iif($accessible_property_str[$getaccessiblepropcode] == $housing.home, 'where you currently live.', 'which is currently  empty.')>>
				<<elseif getvar("$accessible_property["+$getaccessiblepropcode+"]") == 2>>
					<<setinit $property_status_display[$j] = 'You own the $property_display[$j] ' + iif($accessible_property_str[$getaccessiblepropcode] == $housing.home, 'where you currently live.', 'which is currently  empty.')>>
				<<elseif getvar("$accessible_property["+$getaccessiblepropcode+"]") == 3>>
					<<setinit $property_status_display[$j] = 'You own the $property_display[$j] which is currently occupied by your tenants'>>
				<<else>>
					<<setinit $property_status_display[$j] = 'You can stay at the $property_display[$j] which is currently occupied by your tenants'>>
				<</if>>
				<<setinit $property_status[$j] = $accessible_property[$getaccessiblepropcode]>>
				<<setinit $property_construction_status[$j] = $accessible_property[$getaccessiblepropcode + '-construction-status']>>
				<<setinit $property_is_renovated[$j] = $accessible_property[$getaccessiblepropcode + '-renovated']>>
				<<setinit $property_type[$j] = $accessible_property[$getaccessiblepropcode + '-type']>>
				<<set $j += 1>>
			<</if>>
		<</if>>
	<</for>>
<</if>>
<!-- !! Use it as `gs`, creates a set of arrays that contains the relevant info for-->
<!-- !! all properties that are for sale.-->
<!-- !!-->
<!-- !! "Returns":-->
<!-- !! $property_code[], $property_name[], $property_display[], $property_type[]-->
<!-- !! property_construction_status,property_is_renovated[], property_sales_price[], property_renovation_value[]-->
<!-- !!-->
<!-- !! $ARGS[1] - the class of the property: 'home' - returns only homes; 'business' - returns only business properties; '' - returns both types-->

<<if $location_var[$here][0] == 'get_properties_for_sale'>>

	<<set $j = 0>>
	<<gs 'homes_properties' 'clean_up_property_data'>>
	<<set $count = ARRSIZE('home_name')>>

	<<for $i = 0; $i < $count; $i += 1>>
		<<set $getforsalespropcode = $home_name[$i]>>
		<<if $getforsalespropcode != '' and getvar("$checked_homes["+$getforsalespropcode+"]") == 0 and getvar("$accessible_property["+$getforsalespropcode+"]") < 2>>
			<<setinit $checked_homes[$getforsalespropcode] = 1>>
			<<if $accessible_property[$getforsalespropcode] == ''>>
				<<gs 'homes_properties_attr' 'get_property_attr' $getforsalespropcode>>
			<</if>>
			<<set $ishome = iif(!$accessible_property[$getforsalespropcode], INSTR($property['type'], 'residence') > 0, INSTR($accessible_property_str[$$getforsalespropcode+'-type'], 'residence') > 0 )>>
			<<set $hasprice = iif(!$accessible_property_str[$getforsalespropcode], $property['price'] > 0, $accessible_property[$$getforsalespropcode+'-sales-price'] > 0)>>
			<<if (($location_var[$here][1] != 'home' and getvar("$ishome") == 0) or ($location_var[$here][1] != 'business' and $ishome)) and $hasprice>>
				<<setinit $property_code[$j] = $getforsalespropcode>>
				<<setinit $property_name[$j] = iif(!$accessible_property_str[$getforsalespropcode], $property['name'], $accessible_property_str[$getforsalespropcode+'-name'])>>
				<<setinit $property_type[$j] = iif(!$accessible_property_str[$getforsalespropcode], $property['type'], $accessible_property_str[$getforsalespropcode+'-type'])>>
				<<if getvar("$property['construction_needed']") == 1>>
					<<setinit $property_display[$j] = iif(!$accessible_property_str[$getforsalespropcode], $property['display_0'], $accessible_property_str[$getforsalespropcode+'-display'])>>
				<<else>>
					<<setinit $property_display[$j] = iif(!$accessible_property_str[$getforsalespropcode], $property['display'], $accessible_property_str[$getforsalespropcode+'-display'])>>
				<</if>>
				<<setinit $property_is_rented[$j] = $accessible_property[$getforsalespropcode] = 1>>
				<<setinit $property_construction_status[$j] = iif(!$accessible_property_str[$getforsalespropcode], 0, $accessible_property[$getforsalespropcode+'-construction-status'])>>
				<<setinit $property_is_renovated[$j] = iif(!$accessible_property_str[$getforsalespropcode], 0, $accessible_property[$getforsalespropcode+'-renovated'])>>
				<<setinit $property_sales_price[$j] = iif(!$accessible_property_str[$getforsalespropcode], $property['price'], $accessible_property[$getforsalespropcode+'-sales-price'])>>
				<<set $j += 1>>
			<</if>>
			<<set $property to null>>
		<</if>>
	<</for>>
<</if>>
<!-- !! Use it as `gs`, creates a set of arrays that contains the relevant info for-->
<!-- !! all properties that the player can rent.-->
<!-- !!-->
<!-- !! "Returns":-->
<!-- !! $property_code[], $property_name[], $property_display[]-->
<!-- !! property_days[], property_rent[]-->
<!-- !!-->
<!-- !! $ARGS[1] - the class of the property: 'home' - returns only homes; 'business' - returns only business properties; '' - returns both types-->
<<if $location_var[$here][0] == 'get_properties_for_rent'>>

	<<set $j = 0>>
	<<gs 'homes_properties' 'clean_up_property_data'>>
	<<set $count = ARRSIZE('home_name')>>
	<<for $i = 0;$i < $count;$i += 1>>
		<<set $getpropforrentcode = $home_name[$i]>>
		<<if $getpropforrentcode != '' and getvar("$checked_homes["+$getpropforrentcode+"]") == 0 and getvar("$accessible_property["+$getpropforrentcode+"]") == 0>>
			<<setinit $checked_homes[$getpropforrentcode] = 1>>
			<<if $accessible_property[$getpropforrentcode] == ''>>
				<<gs 'homes_properties_attr' 'get_property_attr' $getpropforrentcode>>

			<</if>>
			<<set $ishome = iif(!$accessible_property_str[$getpropforrentcode], INSTR($property['type'], 'residence') > 1, INSTR($accessible_property_str[$getpropforrentcode+'-type'], 'residence') > 1 )>>
			<<set $isrental = iif(!$accessible_property_str[$getpropforrentcode], $property['rental'] = 1, accessible_property[$getpropforrentcode+'-rental'] = 1 )>>
			<<if (($location_var[$here][1] != 'home' and getvar("$ishome") == 0) or ($location_var[$here][1] != 'business' and $ishome)) and $isrental>>
				<<setinit $property_code[$j] = $getpropforrentcode>>
				<<setinit $property_name[$j] = iif(!$accessible_property_str[$getpropforrentcode], $property['name'], $accessible_property_str[$getpropforrentcode+'-name'])>>
				<<if getvar("$property['construction_needed']") == 1>>
					<<setinit $property_display[$j] = iif(!$accessible_property_str[$getpropforrentcode], $property['display_0'], $accessible_property_str[$getpropforrentcode+'-display'])>>
				<<else>>
					<<setinit $property_display[$j] = iif(!$accessible_property_str[$getpropforrentcode], $property['display'], $accessible_property_str[$getpropforrentcode+'-display'])>>
				<</if>>
				<<setinit $property_days[$j] = iif($accessible_property_str[$getpropforrentcode] = '', 0, $accessible_property[$getpropforrentcode+'-days-left'])>>
				<<setinit $property_rent[$j] = iif($accessible_property_str[$getpropforrentcode] = '', $property['rent'], $accessible_property[$getpropforrentcode+'-rent'])>>
				<<set $j += 1>>
			<</if>>
			<<set $property to null>>
		<</if>>
	<</for>>
	<<set $checked_homes to null>>
<</if>>
<!-- !! Use it as `gs`, creates a set of arrays that contains the relevant info for-->
<!-- !! all properties for which the player can buy an internet subscription-->
<!-- !!-->
<!-- !! "Returns":-->
<!-- !! $property_code[], $property_name[], $property_status[], property__is_current_home[]-->
<!-- !! $property_stat values: 'rented', 'owned', 'tenants', 'no access'-->
<!-- !!-->
<!-- !! $ARGS[1] - the class of the property: 'home' - returns only homes; 'business' - returns only business properties; '' - returns both types-->
<!-- !! $ARGS[2] - '' or 'hasaccess'. 'hasaccess' returns only those internet enabled properties that are purchased or rented by Sveta-->
<!-- !! 		      including ones with tenants.-->
<<if $location_var[$here][0] == 'get_internet_enabled_properties'>>

	<<set $j = 0>>
	<<gs 'homes_properties' 'clean_up_property_data'>>
	<<set $count = ARRSIZE('home_name')>>
	<<for $i = 0; $i < $count;$i += 1>>
		<<set $getnetenabledprocode = $home_name[$i]>>
		<<if getvar("$checked_homes["+$getnetenabledprocode+"]") == 0>>
			<<setinit $checked_homes[$getnetenabledprocode] = 1>>
			<<gs 'homes_properties_attr' 'get_property_attr' $getnetenabledprocode>>
			<<set $accesscheck = ($ARGS[2] = 'hasaccess' and accessible_property[$getnetenabledprocode] ! 0 and accessible_property[$getnetenabledprocode] ! 4) or $ARGS[2] = ''>>
			<<set $typecheck = (($ARGS[1] ! 'home' and INSTR($property['type'], 'residence') = 0) or ($ARGS[1] ! 'business' and INSTR($property['type'], 'residence') > 0))>>
			<<if $accesscheck and $typecheck and $property['internet_enabled']>>
				<<setinit $property_name[$j] = $property['name']>>
				<<setinit $property_code[$j] = $getnetenabledprocode>>
				<<if getvar("$accessible_property["+$getnetenabledprocode+"]") == 0>>
					<<setinit $property_status[$j] = 'no access'>>
				<<elseif getvar("$accessible_property["+$getnetenabledprocode+"]") == 1>>
					<<setinit $property_status[$j] = 'rented'>>
				<<elseif getvar("$accessible_property["+$getnetenabledprocode+"]") == 2>>
					<<setinit $property_status[$j] = 'owned'>>
				<<elseif getvar("$accessible_property["+$getnetenabledprocode+"]") == 3>>
					<<setinit $property_status[$j] = 'tenants'>>
				<</if>>
				<<setinit $property__is_current_home[$j] = ($home["current"] == $getnetenabledprocode)>>
				<<set $j += 1>>
			<</if>>
			<<set $property to null>>
		<</if>>
	<</for>>
<</if>>
<!-- !! Call after using any of the above calls to run killvar on all the temporary variables-->
<<if $location_var[$here][0] == 'clean_up_property_data'>>
<</if>>

<!-- !!----------------------------------------------------------->
<!-- !!  Give and block access to properties - use these if the-->
<!-- !!  property is not bought or rented.-->
<!-- !!  Parents home[], Meynold household, Grandparents house, etc.-->
<!-- !!----------------------------------------------------------->
<!-- !! $ARGS[1]: the location for which the access is set-->
<!-- !!			Accepted values-->
<!-- !!			- property code   -> 'city_apartment', 'homeParents'-->
<!-- !!			- a location      ->  'bedrPar', 'koo2x' - A value that can shop up in $loc-->
<!-- !!			- empty strying   ->  '' - will work as if a location was passed, but will use the actual value of $loc-->
<!-- !!			- A number as str -> '1', '2' - this should be the id of the property-->
<!-- !!			  					NOTE: only added in case someone really want to use the old ids-->
<<if $location_var[$here][0] == 'give_access'>>
	<<set $accesscode = iif(!$ARGS[1], $home_name[$loc], $ARGS[1])>>
	<<gs 'homes_properties' 'set_access' $accesscode 1>>
	<<if $accessible_property['accessible_home_count'] == 1 and $accessible_property[$accesscode + '-is-home'] == 1 and $housing.home == ''>>
		<<gs 'homes_properties' 'set_home' $accesscode>>

	<</if>>
	<<set $accesscode to null>>
<</if>>
<!-- !! $ARGS[1]: the location for which the access is set-->
<!-- !!			Accepted values-->
<!-- !!			- property code   -> 'city_apartment', 'homeParents'-->
<!-- !!			- a location      ->  'bedrPar', 'koo2x' - A value that can shop up in $loc-->
<!-- !!			- empty strying   ->  '' - will work as if a location was passed, but will use the actual value of $loc-->
<!-- !!			- A number as str -> '1', '2' - this should be the id of the property-->
<!-- !!			  					NOTE: only added in case someone really want to use the old ids-->
<<if $location_var[$here][0] == 'block_access'>>
	<<set $blockcode = iif(!$ARGS[1], $home_name[$loc], $ARGS[1])>>
	<<gs 'homes_properties' 'set_access' $blockcode 0>>
	<<if getvar("$accessible_property['accessible_home_count']") == 1 and $housing.home == ''>>
		<<gs 'homes_properties' 'get_accessible_properties' 'home'>>
		<<if $accessible_property[$property_code + '-is-home'] == 1>>
			<<gs 'homes_properties' 'set_home' $property_code>>

		<</if>>
		<<gs 'homes_properties' 'clean_up_property_data'>>
	<</if>>
	<<set $blockcode to null>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'has_access', $ARGS[1])`-->
<!-- !! Returns 0 if Sveta has no access to the property and 1 or -1 if she has access, irrelecant of the type of access-->
<!-- !! - owns the property, rents the property or allowed to stay at the property-->
<!-- !!-->
<!-- !! $ARGS[1]: the location for which the access is set-->
<!-- !!			Accepted values-->
<!-- !!			- property code   -> 'city_apartment', 'homeParents'-->
<!-- !!			- a location      ->  'bedrPar', 'koo2x' - A value that can shop up in $loc-->
<!-- !!			- empty strying   ->  '' - will work as if a location was passed, but will use the actual value of $loc-->
<!-- !!			- A number as str -> '1', '2' - this should be the id of the property-->
<!-- !!			  					NOTE: only added in case someone really want to use the old ids-->
<<if $location_var[$here][0] == 'has_access'>>
	<<set $hasaccesscode = iif(!$ARGS[1], $home_name[$loc], $ARGS[1])>>
	<<set $result = ($accessible_property[$hasaccesscode] > 0 and $accessible_property[$hasaccesscode] != 3)>>
	<<set $hasaccesscode to null>>
<</if>>
<!-- !!----------------------------------------------------------->
<!-- !!  Buy, rent out and sell properties-->
<!-- !!----------------------------------------------------------->
<!-- !! Call: `gs 'homes_properties', 'get_property_sales_info', $ARGS[1]-->
<!-- !! Creates $property_display and property_sales_price for a specific property.-->
<!-- !!-->
<!-- !! $ARGS[1] = the code of the property, e.g. 'city_apartment'-->
<<if $location_var[$here][0] == 'get_property_sales_info'>>
	<<if $accessible_property_str[$location_var[$here][1]] == ''>>
		<<gs 'homes_properties_attr' 'get_property_attr' $location_var[$here][1]>>

	<</if>>
	<<if $property['construction_needed'] == 1>>
		<<set $property_display = iif(!$accessible_property_str[$ARGS[1]], $property['display_0'], $accessible_property_str[$$ARGS[1]+'-display'])>>
	<<else>>
		<<set $property_display = iif(!$accessible_property_str[$ARGS[1]], $property['display'], $accessible_property_str[$ARGS[1]+'-display'])>>
	<</if>>
	<<set $property_sales_price = iif(!$accessible_property_str[$ARGS[1]], $property['price'], $accessible_property[$ARGS[1]+'-sales-price'])>>
	<<set $property to null>>
<</if>>
<!-- !! Call: `gs 'homes_properties', 'buy_property', $ARGS[1], ARGS[2]-->
<!-- !! Makes all the necessary changes to the property status, access, etc.-->
<!-- !! and stores the new sales value for future reference in case Sveta sells the property.-->
<!-- !!-->
<!-- !! $ARGS[1] = the code of the property, e.g. 'city_apartment'-->
<!-- !! ARGS[2] = the final sales price in the transaction-->
<<if $location_var[$here][0] == 'buy_property'>>
	<<gs 'homes_properties' 'set_access' $location_var[$here][1] 2>>
	<<setinit $accessible_property[$ARGS[1] + '-sales-price'] = $ARGS[2]>>
<</if>>
<!-- !! Call: `gs 'homes_properties', 'sell_property', $ARGS[1], ARGS[2]-->
<!-- !! Makes all the necessary changes to the property status, access, etc.-->
<!-- !! and stores the new sales value for future reference in case Sveta buys the property back.-->
<!-- !!-->
<!-- !! $ARGS[1] = the code name of the property, e.g. 'city_apartment'-->
<!-- !! ARGS[2] = the final sales price in the transaction-->
<<if $location_var[$here][0] == 'sell_property'>>
	<<gs 'homes_properties' 'set_access' $location_var[$here][1] 0>>
	<<setinit $accessible_property[$ARGS[1] + '-sales-price'] = $ARGS[2]>>
<</if>>
<!-- !! Call: gs 'homes_properties', 'tenants_move_in', $ARGS[1], ARGS[2], ARGS[3]-->
<!-- !! Makes the necessary changes to the property to track the tenants.-->
<!-- !!-->
<!-- !! $ARGS[1] - the property code of the home that is rented to tenants-->
<!-- !!  ARGS[2] - the tenancy end day-->
<!-- !!  ARGS[3] - the tenancy end month-->
<<if $location_var[$here][0] == 'tenants_move_in'>>
	<<gs 'homes_properties' 'set_access' $location_var[$here][1] 3>>
	<<setinit $accessible_property[$ARGS[1] + '-tenant-day'] = $ARGS[2]>>
	<<setinit $accessible_property[$ARGS[1] + '-tenant-month'] = $ARGS[3]>>
	<<if $housing.home == '' and $accessible_property['accessible_home_count'] == 1>>
		<<gs 'homes_properties' 'get_accessible_properties' 'home'>>
		<<if $accessible_property[$$property_code+'-is-home']>>
			<<gs 'homes_properties' 'set_home' $property_code>>

		<</if>>
		<<gs 'homes_properties' 'clean_up_property_data'>>
	<</if>>
<</if>>
<!-- !! Call: gs 'homes_properties', 'tenants_move_out', $ARGS[1]-->
<!-- !! Makes the necessary changes to the property to track the tenants.-->
<!-- !!-->
<!-- !! $ARGS[1] - the property code of the home that was rented to tenants-->
<<if $location_var[$here][0] == 'tenants_move_out'>>
	<<if $location_var[$here][1] != ''>>
		<<gs 'homes_properties' 'set_access' $location_var[$here][1] 2>>
		<<if $housing.home == '' and $accessible_property[$ARGS[1] + '-is-home'] == 1 and $accessible_property['accessible_home_count'] == 1>>
			<<gs 'homes_properties' 'set_home' $location_var[$here][1]>>

		<</if>>
	<</if>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'tenant_move_out_check')`-->
<!-- !! Returns an array of messages for the tenants that have moved out.-->
<!-- !! Runs every night and sees if any tenants are moving out-->
<!-- !! If the tenants are moving out, the property becomes accessible again-->
<!-- !!-->
<<if $location_var[$here][0] == 'tenant_move_out_check'>>
	<<set $count = ARRSIZE('accessible_property')>>

	<<set $j = 0>>
	<<for $i = 0; $i < $count; $i += 1>>
		<<set $tenantcode = $accessible_property_str[$i]>>
		<<if $home_name[$tenantcode] != '' and getvar("$accessible_property["+$tenantcode+"]") == 3>>
			<<if $accessible_property[$tenantcode + '-tenant-day'] == $time.day and $accessible_property[$tenantcode + '-tenant-month'] == $time.month>>
				<<gs 'homes_properties' 'set_access' $tenantcode 2>>
				<<setinit $result[$j] = '<b><font color="red">Your tenants have moved out from your $accessible_property_str[''+$$tenantcode+'-display'] and your apartment is now vacant.</font></b>'>>
				<<set $j += 1>>
			<</if>>
		<</if>>
	<</for>>
	<<if $accessible_property['accessible_home_count'] == 1 and $housing.home == ''>>
		<<gs 'homes_properties' 'get_accessible_properties' 'home'>>
		<<if $accessible_property[$property_code + '-is-home'] == 1>>
			<<gs 'homes_properties' 'set_home' $property_code>>

		<</if>>
		<<gs 'homes_properties' 'clean_up_property_data'>>
	<</if>>
	<<set $i = 0>>
	<<set $j = 0>>
	<<set $count = 0>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'get_property_sales_price', $ARGS[1])`-->
<!-- !! Returns the actual sales price of the property-->
<!-- !!-->
<!-- !! $ARGS[1] - property code-->
<<if $location_var[$here][0] == 'get_property_sales_price'>>
	<<if $accessible_property[$location_var[$here][1]] != ''>>
	<<set $result = $accessible_property[$ARGS[1] + '-sales-price']>>
	<<else>>
		<<gs 'homes_properties_attr' 'get_property_attr' $location_var[$here][1]>>
		<<set $result = $property['price']>>
		<<set $property to null>>
	<</if>>
<</if>>
<!-- !!----------------------------------------------------------->
<!-- !!  Create, Update and Cancel Rents and related values-->
<!-- !!----------------------------------------------------------->
<!-- !! Call: `gs 'homes_properties', 'rent_property'`, $ARGS[1], ARGS[2]`-->
<!-- !! Rents a property. For now with immediate effect.-->
<!-- !!-->
<!-- !! $ARGS[1] = the code name of the property, e.g. 'city_apartment'-->
<!-- !!  ARGS[2] = the number of days the rent is paid for, optional-->
<<if $location_var[$here][0] == 'rent_property'>>
	<<gs 'homes_properties' 'set_access' $location_var[$here][1] 1>>
	<<gs 'homes_properties' 'set_rent_days' $location_var[$here][1] $ARGS[2]>>
<</if>>
<!-- !! Call: `gs 'homes_properties', 'cancel_rent'`, $ARGS[1]`-->
<!-- !! Cancels the rent. For now with immediate effect.-->
<!-- !!-->
<!-- !! $ARGS[1] = the code name of the property, e.g. 'city_apartment'-->
<<if $location_var[$here][0] == 'cancel_rent'>>
	<<gs 'homes_properties' 'set_access' $location_var[$here][1] 0>>
	<<gs 'homes_properties' 'set_rent_days' $location_var[$here][1] -1>>
	<<if getvar("$accessible_property['accessible_home_count']") == 1 and $housing.home == ''>>
		<<gs 'homes_properties' 'get_accessible_properties' 'home'>>
		<<if $accessible_property[$ARGS[1] + '-is-home'] == 1>>
			<<gs 'homes_properties' 'set_home' $location_var[$here][1]>>

		<</if>>
		<<gs 'homes_properties' 'clean_up_property_data'>>
	<</if>>
<</if>>
<!-- !! Call: `gs 'homes_properties', 'cancel_rent'`, $ARGS[1]`, $ARGS[2]-->
<!-- !!-->
<!-- !! $ARGS[1] - property code of the rental-->
<!-- !! $ARGS[2] - payment method: 'card' or 'cash'-->
<<if $location_var[$here][0] == 'pay_rent'>>
	<<if $location_var[$here][2] == 'card'>>
	<<set $finances.bank -= $accessible_property[$ARGS[1] + '-rent']>>
	<<elseif $location_var[$here][2] == 'cash'>>
		<<set $finances.cash -= $accessible_property[$ARGS[1] + '-rent']>>
	<</if>>
	<<gs 'homes_properties' 'add_rent_days' $location_var[$here][1]>>
<</if>>
<!-- !! Call: `gs 'homes_properties', 'add_rent_days', $ARGS[1], ARGS[2]`-->
<!-- !! Add the number of days passed to the remaining rental days.-->
<!-- !!-->
<!-- !! $ARGS[1] = the code name of the property, e.g. 'city_apartment'-->
<!-- !! ARGS[2] - the number of days to add (can be negative).-->
<!-- !!           if the value is 0 then the code will add the number of days equal to the length of the month-->
<<if $location_var[$here][0] == 'add_rent_days'>>
	<<if $location_var[$here][2] == 0>>
		<<setinit $accessible_property[$ARGS[1] + '-days-left'] += setup.func( "homes_properties", "days_in_month")>>
	<<else>>
		<<setinit $accessible_property[$ARGS[1] + '-days-left'] += $ARGS[2]>>
	<</if>>
<</if>>
<!-- !! Call: `gs 'homes_properties', 'set_rent_days', $ARGS[1], ARGS[2]`-->
<!-- !! Sets the remaining rental days to a specific amount.-->
<!-- !!-->
<!-- !! $ARGS[1] - the code name of the property, e.g. 'city_apartment'-->
<!-- !!  ARGS[2] - the number of days to set to - it is an absolute value-->
<!-- !!			  If the value is zero, it will be set to the length of the month (ie. 28,29,30 or 31 days)-->
<<if $location_var[$here][0] == 'set_rent_days'>>
	<<if $location_var[$here][2] == 0>>
		<<setinit $accessible_property[$ARGS[1] +  '-time.days-left'] = setup.func( "homes_properties", "days_in_month")>>
	<<else>>
		<<setinit $accessible_property[$ARGS[1] +  '-time.days-left'] = $ARGS[2]>>
	<</if>>
<</if>>
<!-- !! Call: `gs 'homes_properties', 'set_rent_amount', $ARGS[1], ARGS[2]`-->
<!-- !! Sets the monthly rent of the property-->
<!-- !!-->
<!-- !! $ARGS[1] - property code-->
<!-- !!  ARGS[2] - the new rent amount-->
<<if $location_var[$here][0] == 'set_rent_amount'>>
	<<if $accessible_property[$ARGS[1]+'-rental'] and $location_var[$here][2] >= 0>>
		<<setinit $accessible_property[$ARGS[1] + '-rent'] = $ARGS[2]>>
	<</if>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'get_rent_days', $ARGS[1])`-->
<!-- !! Returns the remaining rent days for the property-->
<!-- !!-->
<!-- !! $ARGS[1] = the code name of the property, e.g. 'city_apartment'-->
<<if $location_var[$here][0] == 'get_rent_days'>>
	<<set $result = $accessible_property[$ARGS[1] + 'days-left']>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'get_rent_amount', $ARGS[1])`-->
<!-- !! Returns the monthly rent of the property-->
<!-- !!-->
<!-- !! $ARGS[1] - property code-->
<<if $location_var[$here][0] == 'get_rent_amount'>>
	<<if $accessible_property_str[$location_var[$here][1]] != ''>>
		<<set $result = $accessible_property[$ARGS[1] + '-rent']>>
	<<else>>
		<<gs 'homes_properties_attr' 'get_property_attr' $location_var[$here][1]>>
		<<set $result = $property['rent']>>
		<<set $property to null>>
	<</if>>
<</if>>
<!-- !! Call: `gs 'homes_properties', 'progress_property_rent_time'`-->
<!-- !! Decreases the number of days left on the lease.-->
<!-- !!-->
<<if $location_var[$here][0] == 'progress_property_rent_time'>>
	<<gs 'homes_properties' 'get_rented_properties' 1>>
	<<set $count = ARRSIZE('property_code')>>
	<<for $i = 0;$i < $count;$i += 1>>
		<<gs 'homes_properties' 'add_rent_days' $property_code[$i]  -1>>
	<</for>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'days_in_month')`-->
<!-- !! Returns the rent the number of days in a give month.-->
<!-- !!-->
<<if $location_var[$here][0] == 'days_in_month'>>
	<<if $time.month == 1 or $time.month == 3 or $time.month == 5 or $time.month == 7 or $time.month == 8 or $time.month == 10 or $time.month == 12>>
		<<set $result = 31>>
	<<elseif $time.month == 2>>
		<<if ($time.year % 4 == 0 and $time.year % 100 != 0) or $time.year % 400 == 0>>
			<<set $result = 29>>
		<<else>>
			<<set $result = 28>>
		<</if>>
	<<else>>
		<<set $result = 30>>
	<</if>>
<</if>>
<!-- !!----------------------------------------------------------->
<!-- !!  Construction and Renovation of Properties-->
<!-- !!----------------------------------------------------------->
<!-- !! Call: `setup.func('homes_properties', 'get_property_construction_status', $ARGS[1])`-->
<!-- !! $ARGS[1] - the property code or location, if empty it will use $loc-->
<<if $location_var[$here][0] == 'get_property_construction_status'>>
	<<set $constrstatcheckpropcode = iif(!$ARGS[1], $home_name[$loc], $home_name[$ARGS[1]])>>
	<<set $result = $accessible_property[$constrstatcheckpropcode + '-construction-status']>>
	<<set $constrstatcheckpropcode to null>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'progress_construction_status', $ARGS[1])`-->
<!-- !! $ARGS[1] - the property code or location, if empty it will use $loc-->
<<if $location_var[$here][0] == 'progress_construction_status'>>
	<<set $constrstatpropcode = iif(!$ARGS[1], $home_name[$loc], $home_name[$ARGS[1]])>>
	<<if $accessible_property[$constrstatpropcode + '-construction-status'] < 2>>
		<<set $accessible_property[$constrstatpropcode + '-construction-status'] += 1>>
	<</if>>
	<<set $constrstatpropcode to null>>
<</if>>
<!-- !! Call: `setup.func('homes_properties', 'is_property_renovated', $ARGS[1])`-->
<!-- !! $ARGS[1] - the property code or location, if empty it will use $loc-->
<<if $location_var[$here][0] == 'is_property_renovated'>>
	<<set $checkrenpropcode = iif(!$ARGS[1], $home_name[$loc], $home_name[$ARGS[1]])>>
	<<set $result = $accessible_property[$checkrenpropcode + '-renovated']>>
	<<set $checkrenpropcode to null>>
<</if>>
<!-- !! Call: `gs 'homes_properties', 'renovate_property', $ARGS[1], ARGS[2], $ARGS[3]-->
<!-- !!-->
<!-- !! $ARGS[1] - the property code or location, if empty it will use $loc-->
<!-- !!  ARGS[2] - the value of the renovation-->
<!-- !! $ARGS[3] - the part of the property that was renovated - 'bedroom', 'living room', etc.  Optional-->
<<if $location_var[$here][0] == 'renovate_property'>>
	<<set $renovatepropcode = iif(!$ARGS[1], $home_name[$loc], $home_name[$ARGS[1]])>>
	<<setinit $accessible_property[$renovatepropcode + '-renovated'] = 1>>
	<<set $accessible_property[$renovatepropcode+ '-renovation-value'] += $ARGS[2]>>
	<<if $location_var[$here][3] != ''>>
		<<set $accessible_property_str[$renovatepropcode + '-renovations'] += $ARGS[3]>>
	<</if>>
	<<set $renovatepropcode to null>>
<</if>>
<!-- !!----------------------------------------------------------->
<!-- !!  Go to properties, home, free internet checksm etc.-->
<!-- !!----------------------------------------------------------->
<!-- !! Call: `gs 'homes_properties', 'go_home'-->
<!-- !! Takes Sveta to the location where her home can be found-->
<<if $location_var[$here][0] == 'go_home'>>
	<<gt $housing.homeLocation $home['location_arg']>>
<</if>>
<!-- !! Call: `gs 'homes_properties', 'go_straight_home'-->
<!-- !! Takes Sveta to the entracne of her home-->
<<if $location_var[$here][0] == 'go_straight_home'>>
	<<gt $home['entrance'] $home['entrance_arg']>>
<</if>>
<!-- !! Returns 0 if the property doesn''t give free internet access, and 1 or -1 if it does-->
<!-- !!-->
<!-- !! Call: setup.func('homes_properties', 'free_internet_available')-->
<!-- !! $ARGS[1] 	The location to be checked-->
<!-- !! 			Accepted values:-->
<!-- !!			- a property code - 'city_apartment', etc.-->
<!-- !!			- a location - a value that could show up in $loc, like 'bedr' or 'mey_home'-->
<!-- !!			- empty string - in this case the actual $loc value will be used-->
<<if $location_var[$here][0] == 'free_internet_available'>>
	<<gs "homes_properties_attr" "get_property_attr" iif($ARGS[1]== "", $home_name[$loc], $home_name[$ARGS[1]])>>
	<<set $result = ($property["free_internet"] == 1)>>
	<<set $property to null>>
<</if>>
