--
-- Mod: FS19_RealLifeNumbers by Kaj-Aage Henneberg "Ki", ArmChairFarming
-- Script: RealNumbersAnimalTradePrices 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.


Animal sell prices

	Five year National/regional averages are obtained from EUROSTAT or USDA. All prices numbers (except horses)
	are given per 100 kg. To get the sell price per animal, this price must be multiplied by
	the sell weight. 
	
	Buy and sell weights are defined in RealNumbersInitialization.lua. The sell price of a weaner equals the buy price of
	a grower so that there is no cost associated by transforming weaners to growers to finishers. For this reason the 
	transport fee is set to zero for these animals.

Horses
	Horses increase in value if they are healthy, clean and well trained. Horses are not sold for slaughter, hence
	their sell weight is irrelevant. Buy and sell prices for horses are set in separate variables and not included
	in the table animalPricePer100kg.

]]--


RealNumbersAnimalTradePrices = {};


function RealNumbersAnimalTradePrices:loadMap(name)
	local currency = "€";		-- or  "$" or "£"
    local textWidth = 40; 		-- text width in log file
	local isDebug = RN.isDebug; -- Change to False when not debugging
	local isDebug1 = false;  	-- Change to False when not dumping fillType to log file
	local isDebug2 = false;  	-- Change to False when not wanting to dump tables to log file
    local iFillType = 0;
	local animalcolor = " ";
	local animalType = " ";
	local transportFee = 0;
	local matureWeight = 0;
	local buyWeight = 0;
	local sellWeight = 0;
	local animalPricePer100kg = 0;
	local buyPrice = 0;
	local sellPrice = 0;
	local myAnimalType = {};

	local gameMoneyUnit = g_i18n.moneyUnit;
	if gameMoneyUnit == 1 then
        currency = "€";
	elseif gameMoneyUnit == 2 then
        currency = "$";
	elseif gameMoneyUnit == 3 then
        currency = "£";
	end;

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


	if isDebug then print("----------------------PIGS----------------------\n") end;

	for k = 1, 4 do
		animalColor = 	RN.pigs.color[k];
		animalType = RN.pigs.type[k];
		transportFee = RN.pigs.transportFee[k]
		iFillType = RN.pigs.fillType[k];
		matureWeight = RN.pigs.matureWeight[k];
		buyWeight = RN.pigs.buyWeight[k];
		sellWeight = RN.pigs.sellWeight[k];
		animalPricePer100kg = RN.pigs.pricePer100kg[k];

		buyPrice = buyWeight * animalPricePer100kg/100;
		sellPrice = sellWeight * animalPricePer100kg/100;

		if isDebug then
			print(" ");
			print(animalType);
			print(" ");
			myPrint(animalColor.." fillType",iFillType,textWidth," ");
			myPrint(animalColor.." animalMatureWeight",matureWeight,textWidth," kg");
			myPrintFloat(animalColor.." animalBuyWeight",buyWeight,textWidth," kg");
			myPrintFloat(animalColor.." animalSellWeight",sellWeight,textWidth," kg");
			myPrintFloat(animalColor.." buyprice",buyPrice,textWidth,currency.."/head");
			myPrintFloat(animalColor.." sellprice",sellPrice,textWidth,currency.."/head");
			myPrintFloat(animalColor.." transportFee",transportFee,textWidth,currency.."/head");
			print(" ");
		end;

		myAnimalType = g_animalManager:getAnimalByFillType(iFillType);
		myAnimalType.storeInfo.buyPrice = buyPrice;
		myAnimalType.storeInfo.sellPrice = sellPrice;
		myAnimalType.storeInfo.transportPrice = transportFee;
		myAnimalType.fillTypeDesc.pricePerLiter = sellPrice;
		myAnimalType.fillTypeDesc.startPricePerLiter = sellPrice;
		myAnimalType.fillTypeDesc.previousHourPrice = sellPrice;
	end;

	if isDebug then print("----------------------COWS----------------------\n") end;

	for k = 1, 4 do
		animalColor = 	RN.cows.color1[k];
		animalType = RN.cows.type[k];
		transportFee = RN.cows.transportFee[k]
		iFillType = RN.cows.fillType1[k];
		matureWeight = RN.cows.matureWeight[k];
		buyWeight = RN.cows.buyWeight[k];
		sellWeight = RN.cows.sellWeight[k];
		animalPricePer100kg = RN.cows.pricePer100kg[k];

		buyPrice = buyWeight * animalPricePer100kg/100;
		sellPrice = sellWeight * animalPricePer100kg/100;

		if isDebug then
			print(" ");
			print(animalType);
			print(" ");
			myPrint(animalColor.." fillType",iFillType,textWidth," ");
			myPrint(animalColor.." animalMatureWeight",matureWeight,textWidth," kg");
			myPrintFloat(animalColor.." animalBuyWeight",buyWeight,textWidth," kg");
			myPrintFloat(animalColor.." animalSellWeight",sellWeight,textWidth," kg");
			myPrintFloat(animalColor.." buyprice",buyPrice,textWidth,currency.."/head");
			myPrintFloat(animalColor.." sellprice",sellPrice,textWidth,currency.."/head");
			myPrintFloat(animalColor.." transportFee",transportFee,textWidth,currency.."/head");
			print(" ");
		end;

		myAnimalType = g_animalManager:getAnimalByFillType(iFillType);
		myAnimalType.storeInfo.buyPrice = buyPrice;
		myAnimalType.storeInfo.sellPrice = sellPrice;
		myAnimalType.storeInfo.transportPrice = transportFee;
		myAnimalType.fillTypeDesc.pricePerLiter = sellPrice;
		myAnimalType.fillTypeDesc.startPricePerLiter = sellPrice;
		myAnimalType.fillTypeDesc.previousHourPrice = sellPrice;
	end;

	for k = 1, 4 do
		animalColor = 	RN.cows.color2[k];
		animalType = RN.cows.type[k];
		transportFee = RN.cows.transportFee[k]
		iFillType = RN.cows.fillType2[k];
		matureWeight = RN.cows.matureWeight[k];
		buyWeight = RN.cows.buyWeight[k];
		sellWeight = RN.cows.sellWeight[k];
		animalPricePer100kg = RN.cows.pricePer100kg[k];

		buyPrice = buyWeight * animalPricePer100kg/100;
		sellPrice = sellWeight * animalPricePer100kg/100;

		if isDebug then
			print(" ");
			print(animalType);
			print(" ");
			myPrint(animalColor.." fillType",iFillType,textWidth," ");
			myPrint(animalColor.." animalMatureWeight",matureWeight,textWidth," kg");
			myPrintFloat(animalColor.." animalBuyWeight",buyWeight,textWidth," kg");
			myPrintFloat(animalColor.." animalSellWeight",sellWeight,textWidth," kg");
			myPrintFloat(animalColor.." buyprice",buyPrice,textWidth,currency.."/head");
			myPrintFloat(animalColor.." sellprice",sellPrice,textWidth,currency.."/head");
			myPrintFloat(animalColor.." transportFee",transportFee,textWidth,currency.."/head");
			print(" ");
		end;

		myAnimalType = g_animalManager:getAnimalByFillType(iFillType);
		myAnimalType.storeInfo.buyPrice = buyPrice;
		myAnimalType.storeInfo.sellPrice = sellPrice;
		myAnimalType.storeInfo.transportPrice = transportFee;
		myAnimalType.fillTypeDesc.pricePerLiter = sellPrice;
		myAnimalType.fillTypeDesc.startPricePerLiter = sellPrice;
		myAnimalType.fillTypeDesc.previousHourPrice = sellPrice;
	end;	

	if isDebug then print("----------------------SHEEP----------------------\n") end;

	for k = 1, 4 do
		animalColor = 	RN.sheep.color[k];
		animalType = RN.sheep.type[k];
		transportFee = RN.sheep.transportFee[k]
		iFillType = RN.sheep.fillType[k];
		matureWeight = RN.sheep.matureWeight[k];
		buyWeight = RN.sheep.buyWeight[k];
		sellWeight = RN.sheep.sellWeight[k];
		animalPricePer100kg = RN.sheep.pricePer100kg[k];

		buyPrice = buyWeight * animalPricePer100kg/100;
		sellPrice = sellWeight * animalPricePer100kg/100;

		if isDebug then
			print(" ");
			print(animalType);
			print(" ");
			myPrint(animalColor.." fillType",iFillType,textWidth," ");
			myPrint(animalColor.." animalMatureWeight",matureWeight,textWidth," kg");
			myPrintFloat(animalColor.." animalBuyWeight",buyWeight,textWidth," kg");
			myPrintFloat(animalColor.." animalSellWeight",sellWeight,textWidth," kg");
			myPrintFloat(animalColor.." buyprice",buyPrice,textWidth,currency.."/head");
			myPrintFloat(animalColor.." sellprice",sellPrice,textWidth,currency.."/head");
			myPrintFloat(animalColor.." transportFee",transportFee,textWidth,currency.."/head");

			print(" ");
		end;

		myAnimalType = g_animalManager:getAnimalByFillType(iFillType);
		myAnimalType.storeInfo.buyPrice = buyPrice;
		myAnimalType.storeInfo.sellPrice = sellPrice;
		myAnimalType.storeInfo.transportPrice = transportFee;
		myAnimalType.fillTypeDesc.pricePerLiter = sellPrice;
		myAnimalType.fillTypeDesc.startPricePerLiter = sellPrice;
		myAnimalType.fillTypeDesc.previousHourPrice = sellPrice;
	end;	

	if isDebug then print("----------------------CHICKEN----------------------\n") end;

	for k = 1, 4 do
		animalColor = 	RN.chicken.color[k];
		animalType = RN.chicken.type[k];
		transportFee = RN.chicken.transportFee[k]
		iFillType = RN.chicken.fillType[k];
		matureWeight = RN.chicken.matureWeight[k];
		buyWeight = RN.chicken.buyWeight[k];
		sellWeight = RN.chicken.sellWeight[k];
		animalPricePer100kg = RN.chicken.pricePer100kg[k];

		buyPrice = buyWeight * animalPricePer100kg/100;
		sellPrice = sellWeight * animalPricePer100kg/100;

		if isDebug then
			print(" ");
			print(animalType);
			print(" ");
			myPrint(animalColor.." fillType",iFillType,textWidth," ");
			myPrint(animalColor.." animalMatureWeight",matureWeight,textWidth," kg");
			myPrintFloat(animalColor.." animalBuyWeight",buyWeight,textWidth," kg");
			myPrintFloat(animalColor.." animalSellWeight",sellWeight,textWidth," kg");
			myPrintFloat(animalColor.." buyprice",buyPrice,textWidth,currency.."/head");
			myPrintFloat(animalColor.." sellprice",sellPrice,textWidth,currency.."/head");
			myPrintFloat(animalColor.." transportFee",transportFee,textWidth,currency.."/head");
			print(" ");
		end;

		myAnimalType = g_animalManager:getAnimalByFillType(iFillType);
		myAnimalType.storeInfo.buyPrice = buyPrice;
		myAnimalType.storeInfo.sellPrice = sellPrice;
		myAnimalType.storeInfo.transportPrice = transportFee;
		myAnimalType.fillTypeDesc.pricePerLiter = sellPrice;
		myAnimalType.fillTypeDesc.startPricePerLiter = sellPrice;
		myAnimalType.fillTypeDesc.previousHourPrice = sellPrice;
	end;
	
	if isDebug then 
		myPrint("Horses buyprice",RN.horses.buyPrice,textWidth,currency.."/head");
		myPrint("Horses sellprice if peak condition",RN.horses.sellPrice,textWidth,currency.."/head");
		print(" ");
   end;

    for k = 1,8 do	
	    iFillType = RN.horses.fillType[k];
		myAnimalType = g_animalManager:getAnimalByFillType(iFillType);
		myAnimalType.storeInfo.buyPrice = RN.horses.buyPrice;
		myAnimalType.storeInfo.sellPrice = RN.horses.sellPrice;
		myAnimalType.storeInfo.transportPrice = RN.horses.transportFee;
		myAnimalType.fillTypeDesc.pricePerLiter = RN.horses.buyPrice;
		myAnimalType.fillTypeDesc.startPricePerLiter = RN.horses.buyPrice;
		myAnimalType.fillTypeDesc.previousHourPrice = RN.horses.buyPrice;
	end;
end;


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

addModEventListener(RealNumbersAnimalTradePrices);
