from tradingmanager.lua

buying:

`-- empty stock -> higher price`

local factor = getNumGoods(goodName) / getMaxStock(good.size) -- 0 to 1 where 1 is 'full stock'

factor = 1 - factor -- 1 to 0 where 0 is 'full stock'

factor = factor * 0.4 -- 0.4 to 0

factor = factor + 0.8 -- 1.2 to 0.8; 'no goods' to 'full'

local relationFactor = 1

if sellingFaction then

local sellerIndex = nil

if type(sellingFaction) == "number" then

sellerIndex = sellingFaction

else

sellerIndex = sellingFaction.index

end

if sellerIndex then

local relations = Faction():getRelations(sellerIndex)

if relations < -10000 then

-- bad relations: faction pays less for the goods

-- 10% to 100% from -100.000 to -10.000

relationFactor = lerp(relations, -100000, -10000, 0.1, 1.0)

elseif relations >= 50000 then

-- very good relations: factions pays MORE for the goods

-- 100% to 120% from 80.000 to 100.000

relationFactor = lerp(relations, 80000, 100000, 1.0, 1.15)

end

if Faction().index == sellerIndex then relationFactor = 0 end

end

end

return round(good.price * relationFactor * factor * buyPriceFactor)

selling:

`local factor = getNumGoods(goodName) / getMaxStock(good.size) -- 0 to 1 where 1 is 'full stock'`

factor = 1 - factor -- 1 to 0 where 0 is 'full stock'

factor = factor * 0.4 -- 0.4 to 0

factor = factor + 0.8 -- 1.2 to 0.8; 'no goods' to 'full'

local relationFactor = 1

if buyingFaction then

local sellerIndex = nil

if type(buyingFaction) == "number" then

sellerIndex = buyingFaction

else

sellerIndex = buyingFaction.index

end

if sellerIndex then

local relations = Faction():getRelations(sellerIndex)

if relations < -10000 then

-- bad relations: faction wants more for the goods

-- 200% to 100% from -100.000 to -10.000

relationFactor = lerp(relations, -100000, -10000, 2.0, 1.0)

elseif relations > 30000 then

-- good relations: factions start giving player better prices

-- 100% to 80% from 30.000 to 90.000

relationFactor = lerp(relations, 30000, 90000, 1.0, 0.8)

end

if Faction().index == sellerIndex then relationFactor = 0 end

end

end

return round(good.price * relationFactor * factor * sellPriceFactor)