# homes_properties

if ARRSIZE('homes') < 16 or ARRSIZE('home_name') < 7: 
	gs 'homes_properties_attr'
end

!!-----------------------------------------------------------------------------------------------------
!!
!!   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 will not have to worry about this, as it will calculate correctly.
!! 
!! ARGS[1] - property type filter: 'home', 'business', 'all' or '' or missing
if $ARGS[0] = 'calculate_rentable_property_count':
	count = ARRSIZE('homes')
	if count > 0:
		:get_rentable_property_count_loop
			gs 'homes_properties_attr', 'get_property_attr', $homes[i]
			if $ARGS[1] ! 'home' and INSTR($property['type'], 'residence') = 0 and property['rental']: 
				accessible_property['rentable_business_count'] += 1
			elseif $ARGS[1] ! 'business' and INSTR($property['type'], 'business') = 0 and property['rental']: 
				accessible_property['rentable_home_count'] += 1
			end
			i += 1
		if i < count: jump 'get_rentable_property_count_loop'
	end
	if accessible_property['rentable_business_count'] = 0: accessible_property['rentable_business_count'] = -1
	if accessible_property['rentable_home_count'] = 0: accessible_property['rentable_home_count'] = -1

	accessible_property['available_for_rent_home_count'] = accessible_property['rentable_home_count']
	accessible_property['available_for_rent_business_count'] = accessible_property['rentable_business_count']
end


!! 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 $ARGS[0] = 'set_home':
	$homepropcode = iif($ARGS[1] = '', $home_name[$loc], $home_name[$ARGS[1]])
	if $homepropcode ! '':
		killvar 'home'
		gs 'homes_properties_attr', 'get_property_attr', $homepropcode
		if INSTR($property['type'], 'residence') > 0:
			COPYARR 'home','property'
			$home['current'] = $property['code']
			if accessible_property[$home['current']] = 0: gs 'homes_properties', 'set_access', $home['current'], 1
			killvar 'property'
		end
	end
end

!! 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', 'parents_home'
!!			- 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 $ARGS[0] = 'set_access':
	$propcode = iif($ARGS[1] = '', $home_name[$loc], $home_name[$ARGS[1]])
	orig_status_code = accessible_property[$propcode]
	new_status_code = ARGS[2]
	if orig_status_code ! new_status_code:
		if $accessible_property[$propcode] = '' or accessible_property['<<$propcode>>-display'] = '' or accessible_property['<<$propcode>>-name'] = '':
			if $property['code'] ! $propcode: 				
				gs 'homes_properties_attr', 'get_property_attr', $propcode	
			else
				nokill = 1
			end
			if ARGS[2] = 1 and property['rental'] = 0: new_status_code = 4
			accessible_property[$propcode] = new_status_code
			$accessible_property[$propcode] = $propcode
			$accessible_property['<<$propcode>>-name'] = $property['name']
			$accessible_property['<<$propcode>>-type'] = $property['type']

			if property['construction_needed'] = 1:
				accessible_property['<<$propcode>>-construction-status'] = ARGS[3]
				$accessible_property['<<$propcode>>-display'] = $property['display_<<ARGS[3]>>']
			else
				accessible_property['<<$propcode>>-construction-status'] = 2
				$accessible_property['<<$propcode>>-display'] = $property['display']
			end

			if INSTR($property['type'], 'residence') > 0: accessible_property['<<$propcode>>-is-home'] = 1
			accessible_property['<<$propcode>>-rental'] = property['rental']
			accessible_property['<<$propcode>>-renovated'] = ARGS[4]
			accessible_property['<<$propcode>>-sales-price'] = property['price']
			accessible_property['<<$propcode>>-rent'] = property['rent']
		end

		if accessible_property[$propcode] = 0:
			!! If this was the current home then killing it
			if $home['current'] = $propcode: killvar '$home'
			
			!! Updating home counts
			!! NOTE: Valid transitions: 1 -> 0, 2 -> 0, 4 -> 0
			if accessible_property['<<$propcode>>-is-home'] = 1:
				if orig_status_code = 1: 
					accessible_property['rental_home_count'] -= 1
					accessible_property['available_for_rent_home_count'] += 1
				end
				if orig_status_code = 2: accessible_property['owned_home_count'] -= 1
				if accessible_property['<<$propcode>>-construction-status'] = 2: accessible_property['furnishable_home_count'] -= 1
				accessible_property['accessible_home_count'] -= 1
			end
			if 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
				gs 'homes_properties', 'clean_up_property_data'
			end
		!! Property is rented
		elseif accessible_property[$propcode] = 1:
			!! Updating home counts
			!! NOTE: Only valid transition is 0 -> 1
			if accessible_property['<<$propcode>>-is-home'] = 1:
				accessible_property['rental_home_count'] += 1
				accessible_property['accessible_home_count'] += 1
				accessible_property['available_for_rent_home_count'] -= 1
				if accessible_property['<<$propcode>>-construction-status'] = 2: accessible_property['furnishable_home_count'] +=1 
			end
		!! Property is owned
		elseif accessible_property[$propcode] = 2:
			!! Updating home counts
			!! NOTE: Valid transitions: 0 -> 2, 1 -> 2, 3-> 2
			if accessible_property['<<$propcode>>-is-home'] = 1:
				if orig_status_code = 0: 
					accessible_property['accessible_home_count'] += 1
				elseif orig_status_code = 1: 
					accessible_property['rental_home_count'] -= 1 
					accessible_property['available_for_rent_home_count'] += 1
				elseif orig_status_code = 3: 
					accessible_property['tenant_home_count'] -= 1 
					accessible_property['<<$propcode>>-tenant-day'] = -1
					accessible_property['<<$propcode>>-tenant-month'] = -1	
					if accessible_property['<<$propcode>>-construction-status'] = 2: accessible_property['furnishable_home_count'] += 1
				end
				if accessible_property['<<$propcode>>-construction-status'] = 2 and orig_status_code ! 1: accessible_property['furnishable_home_count'] += 1 
				accessible_property['owned_home_count'] += 1
			end
		!! Property has tenants
		elseif accessible_property[$propcode] = 3:
			!! Updating home counts
			!! NOTE: Valid transitions: 2 -> 3
			if accessible_property['<<$propcode>>-is-home'] = 1:
				if $home['current'] = $propcode: killvar '$home'
				
				accessible_property['tenant_home_count'] += 1
				accessible_property['owned_home_count'] -= 1
				accessible_property['accessible_home_count'] -= 1
				
				if accessible_property['<<$propcode>>-construction-status'] = 2: accessible_property['furnishable_home_count'] -= 1
			end
		!! Property is just accessible
		elseif accessible_property[$propcode] = 4:
			!! Updating home counts
			!! NOTE: Valid transitions: 0 -> 4
			if accessible_property['<<$propcode>>-is-home'] = 1:
				accessible_property['accessible_home_count'] += 1
			end
		end
		if nokill = 0 : killvar 'property'
	end
	killvar 'propcode' & killvar 'orig_status_code' & killvar 'new_status_code' & killvar 'nokill'
end

!! Call: dyneval($is_homeless)
$is_homeless = { 
	result = ($home['current'] = 'homeless')
}

!! Call: `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', 'parents_home'
!!			- 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 $ARGS[0] = 'can_live_here':
	$canlivecode = iif($ARGS[1] = '', $home_name[$loc], $home_name[$ARGS[1]])
	result = accessible_property[$canlivecode] > 0 and accessible_property[$canlivecode] ! 3 and func('homes_properties', 'get_property_construction_status', $canlivecode) = 2
	killvar 'canlivecode'
end

!! Call: `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', 'parents_home'
!!			- 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 $ARGS[0] = 'is_current_home':
	$currenthomecode = iif($ARGS[1] = '', $home_name[$loc], $home_name[$ARGS[1]])
	result = $home['current'] = $currenthomecode
	killvar 'currenthomecode'
end

!! Call: `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', 'parents_home'
!!			- 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 $ARGS[0] = 'is_at_a_home':
	$isathomecode = iif($ARGS[1] = '', $home_name[$loc], $home_name[$ARGS[1]])
	result = accessible_property['<<$isathomecode>>-is-home'] = 1
	killvar 'isathomecode'
end

!! Call: `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', 'parents_home'
!!			- 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 $ARGS[0] = 'is_property_of_status':
	$propstatcode = iif($ARGS[2] = '', $home_name[$loc], $home_name[$ARGS[2]])	

	if $ARGS[1] = 'rented':
		result = accessible_property[$propstatcode] = 1
	elseif $ARGS[1] = 'owned':
		result = accessible_property[$propstatcode] = 2
	elseif $ARGS[1] = 'tenants':
		result = accessible_property[$propstatcode] = 3
	elseif $ARGS[1] = 'blocked':
		result = accessible_property[$propstatcode] = 0
	elseif $ARGS[1] = 'hasacces':
		result = accessible_property[$propstatcode] = 4
	elseif $ARGS[1] = 'purchased':
		result = accessible_property[$propstatcode] = 2 or accessible_property[$propstatcode] = 3
	else
		result = 0
	end
	killvar 'propstatcode'
end

!! Call `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', 'parents_home'
!!			- 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 $ARGS[0] = 'get_property_code':
	$result = iif($ARGS[1] = '', $home_name[$loc], $home_name[$ARGS[1]])
end


!!---------------------------------------------------------
!!  Home and Property Counts - FUNC()
!!---------------------------------------------------------

!! Call: `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 $ARGS[0] = 'get_rented_property_count':
	if $ARGS[1] = 'home': 
		result = accessible_property['rental_home_count']
	elseif $ARGS[1] = 'business': 
		result = accessible_property['rental_business_count']
	elseif $ARGS[1] = 'all' or $ARGS[1] = '': 
		result = accessible_property['rental_home_count'] + accessible_property['rental_business_count']
	end
end

!! Call: `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 $ARGS[0] = 'get_accessible_property_count':
	if $ARGS[1] = 'home': 
		result = accessible_property['accessible_home_count']
	elseif $ARGS[1] = 'business': 
		result = accessible_property['accessible_business_count']
	elseif $ARGS[1] = 'all' or $ARGS[1] = '': 
		result = accessible_property['accessible_home_count'] + accessible_property['accessible_business_count']
	end
end

!! Call: `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 $ARGS[0] = 'get_rentable_property_count':
	if $ARGS[1] = 'home': 
		result = accessible_property['rentable_home_count']
	elseif $ARGS[1] = 'business': 
		result = accessible_property['rentable_business_count']
	elseif $ARGS[1] = 'all' or $ARGS[1] = '': 
		result = accessible_property['rentable_home_count'] + accessible_property['rentable_business_count']
	end
end

!! Call: `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 $ARGS[0] = 'get_available_for_rent_property_count':
	if $ARGS[1] = 'home': 
		result = accessible_property['available_for_rent_home_count']
	elseif $ARGS[1] = 'business': 
		result = accessible_property['available_for_rent_business_count']
	elseif $ARGS[1] = 'all' or $ARGS[1] = '': 
		result = accessible_property['available_for_rent_home_count'] + accessible_property['available_for_rent_business_count']
	end
end

!! Call: `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 $ARGS[0] = 'get_furnishable_property_count':
	if $ARGS[1] = 'home':  
		result = accessible_property['furnishable_home_count']
	elseif $ARGS[1] = 'business': 
		result = accessible_property['furnishable_business_count']
	elseif $ARGS[1] = 'all' or $ARGS[1] = '': 
		result = accessible_property['furnishable_home_count'] + accessible_property['furnishable_business_count']
	end
end

!!---------------------------------------------------------
!!  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 $ARGS[0] = 'get_rented_properties':
	i = 0
	j = 0
	gs 'homes_properties', 'clean_up_property_data'
	count = ARRSIZE('accessible_property')
	if count > 0: 
		:get_rented_properties_loop
			$getrentedpropcode = $accessible_property[i]
			if $home_name[$getrentedpropcode] ! '' and accessible_property[i] = 1:
				if ($ARGS[1] ! 'home' and accessible_property['<<$getrentedpropcode>>-is-home'] = 0) or ($ARGS[1] ! 'business' and accessible_property['<<$getrentedpropcode>>-is-home'] = 1):
					$property_code[j] = $getrentedpropcode
					if ARGS[2] = 0:
						$property_name[j] = $accessible_property['<<$getrentedpropcode>>-name']

						$property_display[j] = $accessible_property['<<$getrentedpropcode>>-display']
						property_days[j] = accessible_property['<<$getrentedpropcode>>-days-left']
						property_rent[j] = accessible_property['<<$getrentedpropcode>>-rent']
					end
					j += 1
				end
			end
			i += 1
		if i < count: jump 'get_rented_properties_loop'
	end
	killvar 'count' & killvar 'i' & killvar 'j' & killvar '$getrentedpropcode'
end

!! 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 $ARGS[0] = 'get_owned_properties':
	i = 0
	j = 0
	gs 'homes_properties', 'clean_up_property_data'
	$type = iif($ARGS[2] = '', $ARGS[1], 'all')
	count = iif($ARGS[2] = '', ARRSIZE('accessible_property'), 1)
	if count > 0: 
		!!'<h3>Building Owned Properties List</h3>'
		!!'Count: <b><<count>></b>'
		:get_owned_properties_loop
			$getownedpropcode = iif( $ARGS[2] = '', $accessible_property[i], $ARGS[2] )
			!!'  Index: <b><<i>></b> Code: <b><<$getownedpropcode>></b> Status: <b><<accessible_property[i]>></b>'
			if $home_name[$getownedpropcode] ! '' and (accessible_property[$getownedpropcode] = 2 or 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):
					$property_code[j] = $getownedpropcode
					$property_name[j] = $accessible_property['<<$getownedpropcode>>-name']					
					
					if property['construction_needed'] = 1:
						$property_display[j] = iif($accessible_property[$getownedpropcode] = '', $property['display_0'], $accessible_property['<<$getownedpropcode>>-display'])
					else
						$property_display[j] = iif($accessible_property[$getownedpropcode] = '', $property['display'], $accessible_property['<<$getownedpropcode>>-display'])
					end

					$property_type[j] = $accessible_property['<<$getownedpropcode>>-type']
					if accessible_property[$getownedpropcode] = 3: 
						$property_status_display[j] = 'A(n) <<$property_display[j]>> which is currently occupied by your tenants'
					else
						$property_status_display[j] = 'A(n) <<$property_display[j]>> ' + iif($accessible_property[$getownedpropcode] = $home['current'], 'where you currently live.', 'which is currently empty.')
					end

					property_status[j] = accessible_property[$getownedpropcode]
					property_construction_status[j] = accessible_property['<<$getownedpropcode>>-construction-status']
					property_is_renovated[j] = accessible_property['<<$getownedpropcode>>-renovated']
					property_sales_price[j] = accessible_property['<<$getownedpropcode>>-sales-price']
					property_renovation_value[j] = accessible_property['<<$getownedpropcode>>-renovation-value']
					j += 1
				end
			end
			i += 1
		if i < count: jump 'get_owned_properties_loop'
	end
	killvar 'count' & killvar 'i' & killvar 'j' & killvar 'getownedpropcode'
end

!! 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 $ARGS[0] = 'get_accessible_properties':
	i = 0
	j = 0
	gs 'homes_properties', 'clean_up_property_data'
	count = ARRSIZE('accessible_property')
	if count > 0: 
		:get_accessible_properties_loop
			$getaccessiblepropcode = $accessible_property[i]
			if $home_name[$getaccessiblepropcode] ! '' and accessible_property[$getaccessiblepropcode] > 0:
				if ($ARGS[1] ! 'home' and accessible_property['<<$getaccessiblepropcode>>-is-home'] = 0) or ($ARGS[1] ! 'business' and accessible_property['<<$getaccessiblepropcode>>-is-home'] = 1):
					$property_code[j] = $getaccessiblepropcode
					$property_name[j] = $accessible_property['<<$getaccessiblepropcode>>-name']
					if property['construction_needed'] = 1:
						$property_display[j] = iif($accessible_property[$getaccessiblepropcode] = '', $property['display_0'], $accessible_property['<<$getaccessiblepropcode>>-display'])
					else
						$property_display[j] = iif($accessible_property[$getaccessiblepropcode] = '', $property['display'], $accessible_property['<<$getaccessiblepropcode>>-display'])
					end
					if accessible_property[$getaccessiblepropcode] = 1:
						$property_status_display[j] = 'You rent the <<$property_display[j]>> '+iif($accessible_property[$getaccessiblepropcode] = $home['current'], 'where you currently live.', 'which is currently  empty.')
					elseif accessible_property[$getaccessiblepropcode] = 2: 
						$property_status_display[j] = 'You own the <<$property_display[j]>> ' + iif($accessible_property[$getaccessiblepropcode] = $home['current'], 'where you currently live.', 'which is currently  empty.')
					elseif accessible_property[$getaccessiblepropcode] = 3: 
						$property_status_display[j] = 'You own the <<$property_display[j]>> which is currently occupied by your tenants'
					else
						$property_status_display[j] = 'You can stay at the <<$property_display[j]>> which is currently occupied by your tenants'
					end
					
					property_status[j] = accessible_property[$getaccessiblepropcode]
					property_construction_status[j] = accessible_property['<<$getaccessiblepropcode>>-construction-status']
					property_is_renovated[j] = accessible_property['<<$getaccessiblepropcode>>-renovated']
					property_type[j] = accessible_property['<<$getaccessiblepropcode>>-type']
					j += 1
				end
			end
			i += 1
		if i < count: jump 'get_accessible_properties_loop'
	end
	killvar 'count' & killvar 'i' & killvar 'j' & killvar 'getaccessiblepropcode'
end


!! 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 $ARGS[0] = 'get_properties_for_sale':
	i = 0
	j = 0
	gs 'homes_properties', 'clean_up_property_data'
	count = ARRSIZE('homes')
	if count > 0: 
		:get_properties_for_sale_loop
			$getforsalespropcode = $homes[i]
			if $getforsalespropcode ! '' and checked_homes[$getforsalespropcode] = 0 and accessible_property[$getforsalespropcode] < 2:
				checked_homes[$getforsalespropcode] = 1
				if accessible_property[$getforsalespropcode] = '': 
					gs 'homes_properties_attr', 'get_property_attr', $getforsalespropcode
				end
				ishome = iif(accessible_property[$getforsalespropcode] = '', INSTR($property['type'], 'residence') > 0, INSTR($accessible_property['<<$getforsalespropcode>>-type'], 'residence') > 0 )
				hasprice = iif($accessible_property[$getforsalespropcode] = '', property['price'] > 0, accessible_property['<<$getforsalespropcode>>-sales-price'] > 0)
				if (($ARGS[1] ! 'home' and ishome = 0) or ($ARGS[1] ! 'business' and ishome)) and hasprice:
					$property_code[j] = $getforsalespropcode
					$property_name[j] = iif($accessible_property[$getforsalespropcode] = '', $property['name'], $accessible_property['<<$getforsalespropcode>>-name'])
					$property_type[j] = iif($accessible_property[$getforsalespropcode] = '', $property['type'], $accessible_property['<<$getforsalespropcode>>-type'])
					if property['construction_needed'] = 1:
						$property_display[j] = iif($accessible_property[$getforsalespropcode] = '', $property['display_0'], $accessible_property['<<$getforsalespropcode>>-display'])
					else
						$property_display[j] = iif($accessible_property[$getforsalespropcode] = '', $property['display'], $accessible_property['<<$getforsalespropcode>>-display'])
					end

					property_is_rented[j] = accessible_property[$getforsalespropcode] = 1
					property_construction_status[j] = iif($accessible_property[$getforsalespropcode] = '', 0, accessible_property['<<$getforsalespropcode>>-construction-status'])
					property_is_renovated[j] = iif($accessible_property[$getforsalespropcode] = '', 0, accessible_property['<<$getforsalespropcode>>-renovated'])
					property_sales_price[j] = iif($accessible_property[$getforsalespropcode] = '', property['price'], accessible_property['<<$getforsalespropcode>>-sales-price'])
					j += 1
				end
				killvar 'property'
			end
			i += 1
		if i < count: jump 'get_properties_for_sale_loop'
	end
	killvar 'count' & killvar 'i' & killvar 'j' & killvar 'propcode' & killvar 'checked_homes' & killvar 'ishome' & killvar 'hasprice' & killvar '$getforsalespropcode'
end

!! 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 $ARGS[0] = 'get_properties_for_rent':
	i = 0
	j = 0
	gs 'homes_properties', 'clean_up_property_data'
	count = ARRSIZE('homes')

	if count > 0: 
		:get_properties_for_rent_loop
			$getpropforrentcode = $homes[i]
			if $getpropforrentcode ! '' and checked_homes[$getpropforrentcode] = 0 and accessible_property[$getpropforrentcode] = 0:
				checked_homes[$getpropforrentcode] = 1
				if accessible_property[$getpropforrentcode] = '': gs 'homes_properties_attr', 'get_property_attr', $getpropforrentcode
				ishome = iif($accessible_property[$getpropforrentcode] = '', INSTR($property['type'], 'residence') > 1, INSTR($accessible_property['<<$getpropforrentcode>>-type'], 'residence') > 1 )
				isrental = iif($accessible_property[$getpropforrentcode] = '', property['rental'] = 1, accessible_property['<<$getpropforrentcode>>-rental'] = 1 )
				if (($ARGS[1] ! 'home' and ishome = 0) or ($ARGS[1] ! 'business' and ishome)) and isrental:			
					$property_code[j] = $getpropforrentcode
					$property_name[j] = iif($accessible_property[$getpropforrentcode] = '', $property['name'], $accessible_property['<<$getpropforrentcode>>-name'])
					if property['construction_needed'] = 1:
						$property_display[j] = iif($accessible_property[$getpropforrentcode] = '', $property['display_0'], $accessible_property['<<$getpropforrentcode>>-display'])
					else
						$property_display[j] = iif($accessible_property[$getpropforrentcode] = '', $property['display'], $accessible_property['<<$getpropforrentcode>>-display'])
					end
					
					property_days[j] = iif($accessible_property[$getpropforrentcode] = '', 0, accessible_property['<<$getpropforrentcode>>-days-left'])
					property_rent[j] = iif($accessible_property[$getpropforrentcode] = '', property['rent'], accessible_property['<<$getpropforrentcode>>-rent'])
					j += 1
				end
				killvar 'property'
			end
			i += 1
		if i < count: jump 'get_properties_for_rent_loop'
	end
	killvar 'checked_homes'
	killvar 'count' & killvar 'i' & killvar 'j' & killvar '$getpropforrentcode' & killvar 'ishome' & killvar 'isrental'

end

!! 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 $ARGS[0] = 'get_internet_enabled_properties':
	i = 0
	j = 0
	gs 'homes_properties', 'clean_up_property_data'
	count = ARRSIZE('homes')
	if count > 0: 
		:get_internet_enabled_properties_loop
			$getnetenabledprocode = $homes[i]
			if checked_homes[$getnetenabledprocode] = 0:
				checked_homes[$getnetenabledprocode] = 1
				gs 'homes_properties_attr', 'get_property_attr', $getnetenabledprocode
				accesscheck = ($ARGS[2] = 'hasaccess' and accessible_property[$getnetenabledprocode] ! 0 and accessible_property[$getnetenabledprocode] ! 4) or $ARGS[2] = ''
				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']:
					$property_name[j] = $property['name']
					$property_code[j] = $getnetenabledprocode
					if accessible_property[$getnetenabledprocode] = 0: 
						$property_status[j] = 'no access'
					elseif accessible_property[$getnetenabledprocode] = 1:
						$property_status[j] = 'rented'
					elseif accessible_property[$getnetenabledprocode] = 2: 
						$property_status[j] = 'owned'
					elseif accessible_property[$getnetenabledprocode] = 3: 
						$property_status[j] = 'tenants'
					end

					property__is_current_home[j] = $home['current'] = $getnetenabledprocode
					j += 1
					killvar 'accesscheck' & killvar 'typecheck'
				end
				killvar 'property'
			end
			i += 1
		if i < count: jump 'get_internet_enabled_properties_loop'
	end
	killvar 'count' & killvar 'i' & killvar 'j' & killvar 'propcode' & killvar 'checked_homes'
end


!! Call after using any of the above calls to run killvar on all the temporary variables
if $ARGS[0] = 'clean_up_property_data':
	killvar 'property_rent' & killvar 'property_days' & killvar 'property_code' & killvar 'property_status'
	killvar 'property_name' & killvar 'property_display' & killvar 'property_type' & killvar 'property_status_display'
	killvar 'property_is_rented' & killvar 'property_construction_status' & killvar 'property_is_renovated' 
	killvar 'property_sales_price' & killvar 'property_renovation_value' & killvar 'property__is_current_home'
end

!! If there are no properties that can be used as home, Sveta is homeless. 
if $ARGS[0] = 'set_homeless':
	$home['current'] = 'homeless'
end

!!---------------------------------------------------------
!!  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', 'parents_home'
!!			- 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 $ARGS[0] = 'give_access':
	$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 $home['current'] = '': gs 'homes_properties', 'set_home', $accesscode
	killvar '$accesscode'
end

!! $ARGS[1]: the location for which the access is set
!!			Accepted values
!!			- property code   -> 'city_apartment', 'parents_home'
!!			- 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 $ARGS[0] = 'block_access':
	$blockcode = iif($ARGS[1] = '', $home_name[$loc], $ARGS[1])
	gs 'homes_properties', 'set_access', $blockcode, 0
	if accessible_property['accessible_home_count'] = 1 and ($home['current'] = '' or dyneval($is_homeless)): 
		gs 'homes_properties', 'get_accessible_properties', 'home'
		if accessible_property['<<$property_code>>-is-home'] = 1: gs 'homes_properties', 'set_home', $property_code
		gs 'homes_properties', 'clean_up_property_data'
	elseif accessible_property['accessible_home_count'] < 1:
		gs 'homes_properties', 'set_homeless'
	end
	killvar 'blockcode'
end

!! Call: `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', 'parents_home'
!!			- 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 $ARGS[0] = 'has_access':
	$hasaccesscode = iif($ARGS[1] = '', $home_name[$loc], $ARGS[1])
	result = accessible_property[$hasaccesscode] > 0 and accessible_property[$hasaccesscode] ! 3
	killvar 'hasaccesscode'
end


!!---------------------------------------------------------
!!  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 $ARGS[0] = 'get_property_sales_info':
	if $accessible_property[$ARGS[1]] = '' : gs 'homes_properties_attr', 'get_property_attr', $ARGS[1]
	if property['construction_needed'] = 1:
		$property_display = iif($accessible_property[$ARGS[1]] = '', $property['display_0'], $accessible_property['<<$ARGS[1]>>-display'])
	else
		$property_display = iif($accessible_property[$ARGS[1]] = '', $property['display'], $accessible_property['<<$ARGS[1]>>-display'])
	end
	property_sales_price = iif($accessible_property[$ARGS[1]] = '', property['price'], accessible_property['<<$ARGS[1]>>-sales-price'])
	killvar 'property'
end

!! 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 $ARGS[0] = 'buy_property':
	gs 'homes_properties', 'set_access', $ARGS[1], 2
	accessible_property['<<$ARGS[1]>>-sales-price'] = ARGS[2]
end

!! 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 $ARGS[0] = 'sell_property':
	gs 'homes_properties', 'set_access',$ARGS[1], 0
	accessible_property['<<$ARGS[1]>>-sales-price'] = ARGS[2]
end

!! 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 $ARGS[0] = 'tenants_move_in':
	gs 'homes_properties', 'set_access', $ARGS[1], 3
	accessible_property['<<$ARGS[1]>>-tenant-day'] = ARGS[2]
	accessible_property['<<$ARGS[1]>>-tenant-month'] = ARGS[3]
	if $home['current'] = '' 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
		gs 'homes_properties', 'clean_up_property_data'
	end
end

!! 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 $ARGS[0] = 'tenants_move_out':
	if $ARGS[1] ! '':
		gs 'homes_properties', 'set_access', $ARGS[1], 2
		if $home['current'] = '' and accessible_property['<<$ARGS[1]>>-is-home'] = 1 and accessible_property['accessible_home_count'] = 1: gs 'homes_properties', 'set_home', $ARGS[1]
	end
end

!! Call: `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 $ARGS[0] = 'tenant_move_out_check':
	count = ARRSIZE('accessible_property')
	i = 0
	j = 0
	if count > 0:
		:tenantloop
			$tenantcode = $accessible_property[i]
			if $home_name[$tenantcode] ! '' and accessible_property[$tenantcode] = 3:
				if accessible_property['<<$tenantcode>>-tenant-day'] = day and accessible_property['<<$tenantcode>>-tenant-month'] = month:
					gs 'homes_properties', 'set_access', $tenantcode, 2
					$result[j] = '<b><font color="red">Your tenants have moved out from your <<$accessible_property[''<<$tenantcode>>-display'']>> and your apartment is now vacant.</font></b>'
					j += 1
				end
			end					
			i += 1
			killvar 'property'
		if i < count: jump 'tenantloop'
	end
	if accessible_property['accessible_home_count'] = 1 and $home['current'] = '': 
		gs 'homes_properties', 'get_accessible_properties', 'home'
		if accessible_property['<<$property_code>>-is-home'] = 1: gs 'homes_properties', 'set_home', $property_code
		gs 'homes_properties', 'clean_up_property_data'
	end
	killvar 'i' && killvar 'j' && killvar 'count'
end


!! Call: `func('homes_properties', 'get_property_sales_price', $ARGS[1])`
!! Returns the actual sales price of the property
!!
!! $ARGS[1] - property code
if $ARGS[0] = 'get_property_sales_price':
	if accessible_property[$ARGS[1]] ! '':
		result = accessible_property['<<$ARGS[1]>>-sales-price']
	else
		gs 'homes_properties_attr', 'get_property_attr', $ARGS[1]
		result = property['price']
		killvar 'property'
	end
end

!!---------------------------------------------------------
!!  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 $ARGS[0] = 'rent_property':
	gs 'homes_properties', 'set_access', $ARGS[1], 1
	gs 'homes_properties', 'set_rent_days', $ARGS[1], ARGS[2]
end

!! 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 $ARGS[0] = 'cancel_rent':
	gs 'homes_properties', 'set_access', $ARGS[1], 0
	gs 'homes_properties', 'set_rent_days', $ARGS[1], -1
	if accessible_property['accessible_home_count'] = 1 and $home['current'] = '': 
		gs 'homes_properties', 'get_accessible_properties', 'home'
		if accessible_property['<<$ARGS[1]>>-is-home'] = 1: gs 'homes_properties', 'set_home', $ARGS[1]
		gs 'homes_properties', 'clean_up_property_data'
	end
end

!! 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 $ARGS[0] = 'pay_rent':
	if $ARGS[2] = 'card': 
		karta -= accessible_property['<<$ARGS[1]>>-rent']
	elseif $ARGS[2] = 'cash': 
		money -= accessible_property['<<$ARGS[1]>>-rent']
	end
	gs 'homes_properties', 'add_rent_days', $ARGS[1]
end

!! 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 $ARGS[0] = 'add_rent_days':
	if ARGS[2] = 0:
		accessible_property['<<$ARGS[1]>>-days-left'] += func( 'homes_properties', 'days_in_month')
	else
		accessible_property['<<$ARGS[1]>>-days-left'] += ARGS[2]
	end
end

!! 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 $ARGS[0] = 'set_rent_days':
	if ARGS[2] = 0:
		accessible_property['<<$ARGS[1]>>-days-left'] = func( 'homes_properties', 'days_in_month')
	else
		accessible_property['<<$ARGS[1]>>-days-left'] = ARGS[2]
	end
end

!! 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 $ARGS[0] = 'set_rent_amount':
	if accessible_property['<<$ARGS[1]>>-rental'] and ARGS[2] >= 0 : accessible_property['<<$ARGS[1]>>-rent'] = ARGS[2]
end

!! Call: `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 $ARGS[0] = 'get_rent_days':
	result = accessible_property['<<$ARGS[1]>>-days-left']
end

!! Call: `func('homes_properties', 'get_rent_amount', $ARGS[1])`
!! Returns the monthly rent of the property
!!
!! $ARGS[1] - property code
if $ARGS[0] = 'get_rent_amount':
	if $accessible_property[$ARGS[1]] ! '':
		result = accessible_property['<<$ARGS[1]>>-rent']
	else
		gs 'homes_properties_attr', 'get_property_attr', $ARGS[1]
		result = property['rent']
		killvar 'property'
	end
end

!! Call: `gs 'homes_properties', 'progress_property_rent_time'` 
!! Decreases the number of days left on the lease.
!!
if $ARGS[0] = 'progress_property_rent_time':
	gs 'homes_properties', 'get_rented_properties', 1
	count = ARRSIZE('property_code')
	i = 0
	if count > 0:
		:progress_property_rent_time_loop
			gs 'homes_properties', 'add_rent_days', $property_code[i], -1
			i += 1
		if i < count: jump 'progress_property_rent_time_loop'
	end
	killvar 'property_code' & killvar 'count' & killvar 'i'
end

!! Call: `func('homes_properties', 'days_in_month')`
!! Returns the rent the number of days in a give month.
!! 
if $ARGS[0] = 'days_in_month':
	if month = 1 or month = 3 or month = 5 or month = 7 or month = 8 or month = 10 or month = 12:
		result = 31
	elseif month = 2:
		if ((year mod 4 = 0) and (year mod 100 ! 0)) or (year mod 400 = 0):
			result = 29
		else
			result = 28
		end
	else
		result = 30
	end
end

!!---------------------------------------------------------
!!  Construction and Renovation of Properties
!!---------------------------------------------------------

!! Call: `func('homes_properties', 'get_property_construction_status', $ARGS[1])`
!! $ARGS[1] - the property code or location, if empty it will use $loc
if $ARGS[0] = 'get_property_construction_status':
	$constrstatcheckpropcode = iif($ARGS[1] = '', $home_name[$loc], $home_name[$ARGS[1]])
	result = accessible_property['<<$constrstatcheckpropcode>>-construction-status']
	killvar 'constrstatcheckpropcode'
end

!! Call: `func('homes_properties', 'progress_construction_status', $ARGS[1])`
!! $ARGS[1] - the property code or location, if empty it will use $loc
if $ARGS[0] = 'progress_construction_status':
	$constrstatpropcode = iif($ARGS[1] = '', $home_name[$loc], $home_name[$ARGS[1]])
	if accessible_property['<<$constrstatpropcode>>-construction-status'] < 2: accessible_property['<<$constrstatpropcode>>-construction-status'] += 1
	killvar 'constrstatpropcode'
end

!! Call: `func('homes_properties', 'is_property_renovated', $ARGS[1])`
!! $ARGS[1] - the property code or location, if empty it will use $loc
if $ARGS[0] = 'is_property_renovated':
	$checkrenpropcode = iif($ARGS[1] = '', $home_name[$loc], $home_name[$ARGS[1]])
	result = accessible_property['<<$checkrenpropcode>>-renovated']
	killvar 'checkrenpropcode'
end

!! 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 $ARGS[0] = 'renovate_property':
	$renovatepropcode = iif($ARGS[1] = '', $home_name[$loc], $home_name[$ARGS[1]])
	accessible_property['<<$renovatepropcode>>-renovated'] = 1
	accessible_property['<<$renovatepropcode>>-renovation-value'] += ARGS[2]
	if $ARGS[3] ! '' : $accessible_property['<<$renovatepropcode>>-renovations'] += ';<<$ARGS[3]>>' 
	killvar '$renovatepropcode'
end

!!---------------------------------------------------------
!!  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 $ARGS[0] = 'go_home':
	if dyneval($is_homeless) or $home['region'] ! $region:
		dynamic($train_station[$region])
	else
		gt $home['location'], $home['location_arg']
	end
end

!! Call: `gs 'homes_properties', 'go_straight_home'`
!! Takes Sveta to the entrance of her home
if $ARGS[0] = 'go_straight_home':
	if dyneval($is_homeless) or $home['region'] ! $region:
		dynamic($train_station[$region])
	else
		gt $home['entrance'], $home['entrance_arg']
	end
end

!! Call: `gs 'homes_properties', 'go_bathroom'`
!! Takes Sveta to the bathroom of the property they are at, or the property passed in $ARGS[1]
!! $ARGS[1] - the property code or location, if empty it will use $loc
if $ARGS[0] = 'go_bathroom':
	$name = iif($ARGS[1] = '', $home_name[$loc], $home_name[$ARGS[1]])
	gs 'homes_properties_attr', 'get_property_attr', $name
	gt $property['bathroom'], $property['bathroom_arg']
	killvar '$property'
	killvar '$name'
end

!! Call: `gs 'homes_properties', 'go_bedroom'`
!! Takes Sveta to the bedroom of the property they are at, or the property passed in $ARGS[1]
!! $ARGS[1] - the property code or location, if empty it will use $loc
if $ARGS[0] = 'go_bedroom':
	$name = iif($ARGS[1] = '', $home_name[$loc], $home_name[$ARGS[1]])
	gs 'homes_properties_attr', 'get_property_attr', $name
	gt $property['bedroom'], $property['bedroom_arg']
	killvar '$property'
	killvar '$name'
end


!! Returns 0 if the property doesn''t give free internet access, and 1 or -1 if it does
!!
!! Call: 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 $ARGS[0] = 'free_internet_available':
	gs 'homes_properties_attr', 'get_property_attr', iif($ARGS[1] = '', $home_name[$loc], $home_name[$ARGS[1]])
	result = property['free_internet'] = 1
	killvar 'property'
end

--- homes_properties ---------------------------------