# AppearanceSystem
$this = 'AppearanceSystem'

if $ARGS[0] = '':
	!{
        PC's appearance is updated regularly in stat.qsrc.
        Note: A huge part of PC's appearance is from base appearance, which is updated once a day. Because it's
        a global variable, it does not show in this function in particular, but it's used in 'CalcAppearance'
    }
	if pcs_makeup = 6 and bimbolevel >= 2: extra_supnatvnesh = 2*bimbolevel - 2

	!STD check. STD will make appearance automatically -10
	if Gerpes >= 3 or Sifilis >= 21 or Triper > 2:
		pcs_apprnc = -10
		hotcat = -1
	else
		clothingBonus = func($this, 'CalcClothingBonus')
		accessoriesBonus = func($this, 'CalcAccessoriesBonus', bonusZ, PShoQuality)
		groomingBonus = func($this, 'CalcGroomingBonus')
		groomingPenalty = func($this, 'CalcGroomingPenalty')
		pcs_apprnc = func($this, 'CalcAppearance', (supnatvnesh + extra_supnatvnesh))
		Hotcat = func($this, 'ConvertToHotcat')
	end

	killvar 'clothingBonus'
	killvar 'accessoriesBonus'
	killvar 'groomingBonus'
	killvar 'groomingPenalty'
end

if $args[0] = 'UpdateBaseAppearnce':
	!{
		Base Appearance is updated once a day at midnight and called from cikl
		Base Appearance is calculated from:
			vidage, skin, body shape (fat and strength), attributes (endurance and agility)
	}
	attributeBonus = func($this, 'CalcAttributeBonus')
	skinBonus = pcs_skin / 10
	bodyShapeBonus = func($this, 'SetBodyShapeBonus')
	visibleAgePenalty = func($this, 'CalcVisibleAgePenalty')
	teethPenalty = func($this, 'CalcTeethPenalty')

	! Calculte base appearance
	pcs_apprncbase = skinBonus + bodyShapeBonus + attributeBonus - visibleAgePenalty - teethPenalty + supnatvnesh

end

if $ARGS[0] = 'CalcFaceBonus':
	!!	Setting Eyelashes bonus
	if pcs_lashes <= 0:
		eyelashesBonus = 0
	elseif pcs_lashes = 1:
		eyelashesBonus = 1
	elseif pcs_lashes = 2:
		eyelashesBonus = 3
	elseif pcs_lashes = 3:
		eyelashesBonus = 4
	elseif pcs_lashes = 4:
		eyelashesBonus = 5
	elseif pcs_lashes = 5:
		eyelashesBonus = 6
	else
		eyelashesBonus = 0
	end
	eyelashesBonus = FUNC($this, 'AdjustFromBMI', eyelashesBonus)

	!!	Setting Eye Size bonus
	if pcs_eyesize = 1:
		eyeSizeBonus = 1
	elseif pcs_eyesize = 2:
		eyeSizeBonus = 3
	elseif pcs_eyesize = 3:
		eyeSizeBonus = 2
	else
		eyeSizeBonus = 0
	end
	eyeSizeBonus = FUNC($this, 'AdjustFromBMI', eyeSizeBonus)

	!!	Setting the Lip size bonus
	if pcs_lip = 0:
		lipBonus = -2
	elseif pcs_lip = 1:
		lipBonus = 0
	elseif pcs_lip = 2:
		lipBonus = 1
	elseif pcs_lip = 3:
		lipBonus = 3
	else
		lipBonus = 3
	end
	lipBonus = FUNC($this, 'AdjustFromBMI', lipBonus)

	result = eyelashesBonus + eyeSizeBonus + lipBonus

end

if $ARGS[0] = 'CalcAttributeBonus':
	tempAttributeBonus = (pcs_agil / 5) + (pcs_vital / 5)

	result = func($this, 'AdjustFromBMI', tempAttributeBonus)
	killvar 'tempAttributeBonus'
end

if $ARGS[0] = 'CalcVisibleAgePenalty':
	if vidage < 20:
		tempAttributePenalty =   func('shortgs','round_divide', (5*(20 - vidage)), 2)
	else
		tempAttributePenalty = 0
	end

	result = func($this, 'AdjustFromBMI', tempAttributePenalty)
	killvar 'tempAttributePenalty'
end

if $ARGS[0] = 'CalcTeethPenalty':
	if pcs_teeth > 0:
		tempAttributePenalty =  10 * pcs_teeth
	elseif pcs_teeth = 0:
		tempAttributePenalty = 5
	else
		tempAttributePenalty = 0
	end

	if pcs_missing_teeth > 0:
		tempAttributePenalty +=  10 * pcs_missing_teeth
	end

	result = func($this, 'AdjustFromBMI', tempAttributePenalty)
	killvar 'tempAttributePenalty'
end

if $ARGS[0] = 'SetBodyShapeBonus':
	! Magic uses a different calculation
	if dounspell = 1:
		bodytipe = pcs_hips - pcs_waist
		if bodytipe < 20:
			result = 0
		elseif bodytipe >= 20 and bodytipe < 25:
			result = 2
		elseif (bodytipe >= 25 and bodytipe < 30) or bodytipe >=35:
			result = 4
		elseif bodytipe >= 30 and bodytipe < 35:
			result = 8
		end

	!!Setting the pcs_apprnc bonus based on fat and strength
	else
		if pcs_bmi < 16:
			!! severely underweight
			tempBodyShapeBonus = -10
		elseif pcs_bmi < 19:
			!! underweight
			tempBodyShapeBonus = 25
		elseif pcs_bmi < 25:
			!! healthy weight
			tempBodyShapeBonus = 50
		elseif pcs_bmi < 30:
			!! overweight
			tempBodyShapeBonus = 25
		elseif pcs_bmi < 35:
			!! moderately obese
			tempBodyShapeBonus = 10
		elseif pcs_bmi < 40:
			!! severely obese
			tempBodyShapeBonus = -15
		elseif pcs_bmi < 45:
			!! very severely obese
			tempBodyShapeBonus = -40
		else
			!! morbidly obese
			tempBodyShapeBonus = -80
		end

		if succubusflag = 1:
			tempBodyShapeBonus += 10
		else
			if strenbuf > 180:
				tempBodyShapeBonus -= 70
			elseif strenbuf > 160:
				tempBodyShapeBonus -= 50
			elseif strenbuf > 140:
				tempBodyShapeBonus -= 30
			elseif strenbuf <= 5 or strenbuf > 120:
				tempBodyShapeBonus -= 20
			elseif strenbuf <= 10 or strenbuf > 100:
				tempBodyShapeBonus -= 15
			elseif strenbuf <= 15 or strenbuf > 95:
				tempBodyShapeBonus -= 10
			elseif strenbuf <= 25 or strenbuf > 85:
				tempBodyShapeBonus -= 5
			elseif strenbuf <= 35 or strenbuf > 75:
				tempBodyShapeBonus += 0
			elseif strenbuf <= 45 or strenbuf > 60:
				tempBodyShapeBonus += 5
			else
				tempBodyShapeBonus += 10
			end
		end

		!!This modifies bodykoef for high or low salo values
		if salocatnow = 0 or salocatnow >= 7:
			tempBodyShapeBonus -= 8
		elseif salocatnow = 1 or salocatnow = 6:
			tempBodyShapeBonus -= 4
		end

		if vofat > 0: tempBodyShapeBonus -= vofat

		result = tempBodyShapeBonus

		killvar 'tempBodyShapeBonus'
	end
end

if $ARGS[0] = 'CalcClothingBonus':
	if $clothingworntype = 'nude':
		if pcs_bmi >= 19 and pcs_bmi < 30:
			! Healthy and overweight
			tempRevealing = 405
			PCloQuality = 3
		else
			tempRevealing = 0
			PCloQuality = 1
		end
	else
		if pcs_bmi < 19:
			!Skinny and severely skinny
			tempRevealing = ((400 - PXCloThinness) + (500 - PXCloTopCut) + (400 - PXCloBottomShortness))/2
		elseif pcs_bmi >= 19 and pcs_bmi < 30:
			!Healthy and overweight
			tempRevealing = (PXCloThinness + PXCloTopCut + PXCloBottomShortness)/2
		elseif pcs_bmi >= 30:
			!Moderately overweight and above
			tempRevealing = ((400 - PXCloThinness) + (500 - PXCloTopCut) + (400 - PXCloBottomShortness)) * 3/4
		end
	end

	result = tempRevealing/ 76 * PCloQuality
	killvar 'tempRevealing'

end

if $ARGS[0] = 'CalcAccessoriesBonus':
	coatQualityBonus = ARGS[1] & !! bonusZ
	shoesQualityBonus = ARGS[2] & !! PShoQuality

	!!bonuses for certain underwear
	if $pantyworntype = 'boutique':
		pantyBonus = 4
	elseif $pantyworntype = 'fashionista':
		pantyBonus = 2
	end

	if $braworntype = 'boutique':
		braBonus = 4
	elseif $braworntype = 'fashionista':
		braBonus = 2
	end

	result = coatQualityBonus + shoesQualityBonus + pantyBonus + braBonus

	killvar 'coatQualityBonus'
	killvar 'shoesQualityBonus'
	killvar 'pantyBonus'
	killvar 'braBonus'
end

if $ARGS[0] = 'CalcGroomingBonus':

	makeupBonus = pcs_makupskl/5 - 5
	if pcs_makeup = 0: makeupBonus = -5
	if pcs_makeup = 1: makeupBonus = 0
	if pcs_makeup = 5: makeupBonus = 30

	breathBonus = pcs_breath * 5

	tempGroomingBonus = makeupBonus + breathBonus

	!result = tempGroomingBonus
	result = func($this, 'AdjustFromBMI', tempGroomingBonus)

end

if $ARGS[0] = 'CalcGroomingPenalty':
	if pcs_lipbalm > 0:
		lipBalmPenalty = 0
	else
		lipBalmPenalty = 5
	end

	hairPenalty = (1 - pcs_hairbsh) * 10

	!! buzzcut penalty to pcs_apprnc
	if pcs_hairlng < 10:
		buzzCutPenalty = 10
	else
		buzzCutPenalty = 0
	end

	!!Small penalty for not wearing deodorant, if pcs_sweat is low enough
	if deodorant_on = 0 or pcs_sweat >= 20: deodorantPenalty = 5

	if pcs_sweat < 22:
		sweatPenalty = 0
	elseif temppcs_sweat < 38:
		sweatPenalty = (pcs_sweat - 10) / 4
	elseif temppcs_sweat < 54:
		sweatPenalty = (pcs_sweat - 10) / 2
	else
		sweatPenalty = 3 * (pcs_sweat - 10) / 4
	end

	!Glasses Penalty
	if glass >= 2 or glass = 0:
		glassesPenalty = 0
	elseif glass = 1:
		glassesPenalty = 10
	end

	!hair color fade penalty
	if pcs_haircol ! nathcol:
		if dyefade > 0 and dyefade < 7: hairDyePenalty = 5
		if dyefade = 0: hairDyePenalty = 15
	end

	! Leg hair penalty
	if pcs_leghair <= 0:
		legPenalty = 0
	elseif pcs_leghair <= 3:
		legPenalty = 3
	elseif pcs_leghair <= 6:
		legPenalty = 6
	else
		legPenalty = 9
	end

	result = sweatPenalty + glassesPenalty + hairDyePenalty + buzzCutPenalty + legPenalty + lipBalmPenalty + hairPenalty + deodorantPenalty

end


if $ARGS[0] = 'CalcAppearance':
	superNaturalBonus = ARGS[1] & !! supnatvnesh

	temp_apprnc = pcs_apprncbase + clothingBonus + accessoriesBonus + groomingBonus - groomingPenalty

	if temp_apprnc >= 200: temp_apprnc = 200
	if temp_apprnc < 0: temp_apprnc = 0

	!Any super natural bonuses are allowed to go above the max scale
	result = temp_apprnc + superNaturalBonus

end

if $ARGS[0] = 'ConvertToHotcat':
	if pcs_apprnc <= 40:
		result = 1
	elseif pcs_apprnc <= 60:
		result = 2
	elseif pcs_apprnc <= 80:
		result = 3
	elseif pcs_apprnc <= 100:
		result = 4
	elseif pcs_apprnc <= 125:
		result = 5
	elseif pcs_apprnc <= 150:
		result = 6
	elseif pcs_apprnc <= 165:
		result = 7
	elseif pcs_apprnc <= 180:
		result = 8
	elseif pcs_apprnc <= 199:
		result = 9
	else
		result = 10
	end
end

if $ARGS[0] = 'AdjustFromBMI':
	tempValue = ARGS[1] & !!value to be adjusted

	if pcs_bmi < 16:
		!! severely underweight
		tempValue = tempValue * 50 / 100
    elseif pcs_bmi < 19:
		!! underweight
		tempValue = tempValue * 95 / 100
    elseif pcs_bmi < 25:
		!! healthy weight
		!! normal bonus
    elseif pcs_bmi < 30:
		!! overweight
		tempValue = tempValue * 95 / 100
    elseif pcs_bmi < 35:
		!! moderately obese
		tempValue = tempValue * 80 / 100
    elseif pcs_bmi < 40:
		!! severely obese
		tempValue = tempValue * 55 / 100
    elseif pcs_bmi < 45:
		!! very severely obese
		tempValue = tempValue * 50 / 100
    else
		!!morbidly obese
		tempValue = tempValue * 40 / 100
    end

	result = tempValue
	killvar 'tempValue'
end
--- AppearanceSystem ---------------------------------
