--
-- Mod: FS19_RealLifeNumbers by Kaj-Aage Henneberg "Ki", ArmChairFarming
-- Script: RealNumbersAnimalProducts by Kaj-Aage Henneberg "Ki", ArmChairFarming
-- e-mail: kaj-aage.henneberg@outlook.dk
-- Download: www.modhoster.com
-- All rights reserved.
-- Version 1.1.4.0
-- 30.11.2018 - 29.06.2019

-- Names for FillTypes

-- WHEAT BARLEY OAT CANOLA SUNFLOWER SOYBEAN MAIZE POTATO SUGARBEET OILSEEDRADISH
-- MANURE SEEDS FORAGE FORAGE_MIXING CHAFF WOODCHIPS SILAGE
-- STRAW GRASS_WINDROW DRYGRASS_WINDROW SUGARCANE FERTILIZER PIGFOOD LIME
-- WOOL TREESAPLINGS EGG
-- MILK FUEL WATER DIESEL DEF
-- LIQUIDFERTILIZER HERBICIDE
-- CHAFF GRASS_WINDROW
-- LIQUIDMANURE DIGESTATE
-- COW_TYPE_BRAHMAN_GREY COW_TYPE_BRAHMAN_LIGHT_BROWN COW_TYPE_BRAHMAN_WHITE
-- COW_TYPE_BRAHMAN_BROWN COW_TYPE_BROWN COW_TYPE_BROWN_WHITE COW_TYPE_BLACK
-- COW_TYPE_BLACK_WHITE
-- SHEEP_TYPE_WHITE SHEEP_TYPE_BROWN SHEEP_TYPE_BLACK_WHITE SHEEP_TYPE_BLACK
-- PIG_TYPE_RED PIG_TYPE_WHITE PIG_TYPE_BLACK_WHITE PIG_TYPE_BLACK
-- CHICKEN_TYPE_BLACK CHICKEN_TYPE_WHITE CHICKEN_TYPE_BROWN CHICKEN_TYPE_ROOSTER

--[[

	Version 1.1
	
	No change.

Product mass density

	Milk density is assumed to be 1.025 kg/L.

	Wool density is based on Wool bales of 480 L and 180 kg yielding 0.375 kg/L.

	Egg density is based on 60 gram per egg and bulk volume of 50 ml/egg, yielding 1.2 kg/L

	Be aware that Farmingsimulator requires density numbers in (metric) Ton/Liter. Hence the numbers listed
	is divided by 1000 when assigning the value to massPerLiter.

	Animal product mass density is considered independent of geographical location.

Product prices

	Product sell prices are 5 years national/regional average values obtained from EUROSTAT or USDA.

]]--

RealNumbersAnimalProducts = {};


function RealNumbersAnimalProducts:loadMap(name)
	local currency = "€";	-- or  "$" or "£"
    local textWidth = 40; 	-- text width in log file
	local iFillType = 0;
	local Item = "Empty";
	local idx = 0;
	local price = 0;
	local randomness = 1; 			--1: on, 0: off
	local randomPriceFactor = 1;
	local massScale = 1000;
	local isDebug = RN.isDebug;  	-- Change to False when no output to log file is wanted
	local animalProduct = RN.animalProduct;
    local animalProductDensity = RN.animalProductDensity;
	local animalProductPricePer100kg = RN.animalProductPricePer100kg ;
	local gameMoneyUnit = g_i18n.moneyUnit;
	if gameMoneyUnit == 1 then 
        currency = "€";
	elseif gameMoneyUnit == 2 then 
        currency = "$";
	elseif gameMoneyUnit == 3 then 
        currency = "£";
	end;

	print("\nFS19_RealLifeNumbers: RealNumbersAnimalProducts active\n")
	



-- MILK

    idx = 1;
    Item = animalProduct[idx];
	randomPriceFactor = 1 + randomness * RN.commodityPriceVariation * (math.random()-0.5)/100;
	price = randomPriceFactor * animalProductDensity[idx]*animalProductPricePer100kg[idx]/100;
    iFillType = g_fillTypeManager:getFillTypeIndexByName('MILK');
	g_currentMission.fillTypeManager.fillTypes[iFillType].massPerLiter = animalProductDensity[idx]/massScale;
    g_currentMission.fillTypeManager.fillTypes[iFillType].pricePerLiter = price;
	g_currentMission.fillTypeManager.fillTypes[iFillType].previousHourPrice = price;
	g_currentMission.fillTypeManager.fillTypes[iFillType].startPricePerLiter = price;
 	if isDebug then
		myPrint(Item.." fillTypeIndex",iFillType,textWidth," ");
		myPrintFloat(Item.." massPerLiter",animalProductDensity[idx],textWidth," kg/L");
		myPrint(Item.." pricePer1000Liter",1000*price,textWidth,currency.."/1000 L");
	end;

-- WOOL

    idx = 2;
    Item = animalProduct[idx];
	randomPriceFactor = 1 + randomness * RN.commodityPriceVariation * (math.random()-0.5)/100;
	price = randomPriceFactor * animalProductDensity[idx]*animalProductPricePer100kg[idx]/100;
    iFillType = g_fillTypeManager:getFillTypeIndexByName('WOOL');
	g_currentMission.fillTypeManager.fillTypes[iFillType].massPerLiter = animalProductDensity[idx]/massScale;
    g_currentMission.fillTypeManager.fillTypes[iFillType].pricePerLiter = price;
	g_currentMission.fillTypeManager.fillTypes[iFillType].previousHourPrice = price;
	g_currentMission.fillTypeManager.fillTypes[iFillType].startPricePerLiter = price;
 	if isDebug then
		myPrint(Item.." fillTypeIndex",iFillType,textWidth," ");
		myPrintFloat(Item.." massPerLiter",animalProductDensity[idx],textWidth," kg/L");
		myPrint(Item.." pricePer1000Liter",1000*price,textWidth,currency.."/1000 L");
	end;

-- EGG

    idx = 3;
    Item = animalProduct[idx];
	randomPriceFactor = 1 + randomness * RN.commodityPriceVariation * (math.random()-0.5)/100;
	price = randomPriceFactor * animalProductDensity[idx]*animalProductPricePer100kg[idx]/100;
    iFillType = g_fillTypeManager:getFillTypeIndexByName('EGG');
	g_currentMission.fillTypeManager.fillTypes[iFillType].massPerLiter = animalProductDensity[idx]/massScale;
    g_currentMission.fillTypeManager.fillTypes[iFillType].pricePerLiter = price;
	g_currentMission.fillTypeManager.fillTypes[iFillType].previousHourPrice = price;
	g_currentMission.fillTypeManager.fillTypes[iFillType].startPricePerLiter = price;
 	if isDebug then
		myPrint(Item.." fillTypeIndex",iFillType,textWidth," ");
		myPrintFloat(Item.." massPerLiter",animalProductDensity[idx],textWidth," kg/L");
		myPrint(Item.." pricePer1000Liter",1000*price,textWidth,currency.."/1000 L");
	end;


end;


function RealNumbersAnimalProducts:keyEvent(unicode, sym, modifier, isDown)
end;
function RealNumbersAnimalProducts:update(dt)
end;
function RealNumbersAnimalProducts:draw()
end;
function RealNumbersAnimalProducts:deleteMap()
end;
function RealNumbersAnimalProducts:mouseEvent(posX, posY, isDown, isUp, button)
end;

addModEventListener(RealNumbersAnimalProducts);
