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

RealNumbersFarmland = {};


function myPrintFieldInfo5(farmlandId, landArea,  landPrice, currency, owned)
	print(string.format("Farmland %3.0f: Land area = %4.1f ha,  Price = %7.0f %s, Ownership: %s",  farmlandId*1.0, landArea, landPrice*1.0, tostring(currency), tostring(owned)));
end;

function  myPrintFieldInfo6(fieldId, fieldArea, fruitName)
print(string.format("              Field %3.0f: Field area = %4.1f ha,   Fruit: %s",  fieldId*1.0, fieldArea, tostring(fruitName)));
end;

function RealNumbersFarmland:loadMap()
	print("\nFS19_RealLifeNumbers: RealNumbersFarmland active,  press lAlt-rt");
	print("-- Lists fields in farmland order\n");
end;

function RealNumbersFarmland:keyEvent(unicode, sym, modifier, isDown)
	local currency = " ";
	local isDebug = true;
	local isDebug2 = false;

    local textWidth = 40;
	local Fruits = {"Wheat", "Barley", "Oat", "Cotton", "Canola", "Sunflower", "Soybean", "Maize", "Potato", "Sugarbeet", "Oilseed Radish", "Poplar","Grass","Drygrass","Sugarcane","Weed"};
	local gameMoneyUnit = g_i18n.moneyUnit;
	if gameMoneyUnit == 1 then
        currency = "€";
	elseif gameMoneyUnit == 2 then
        currency = "$";
	elseif gameMoneyUnit == 3 then
        currency = "£";
	end;


	local farmland = {};
	local farmlandId = 0;
	local farmlandArea = 0;
	local farmlandPrice = 0;
	local farmlandIsOwned = false;

	local fieldId = 0;
	local fieldArea = 0;
	local fruitName = "Undefined";
	local fruitTypeIndex = 0;
	
	if Input.isKeyPressed(Input.KEY_lalt) and Input.isKeyPressed(Input.KEY_r) and Input.isKeyPressed(Input.KEY_t) then
		print("\nLeft Alt-rt pressed\n");
		print("Map                   : "..g_currentMission.missionInfo.map.title.." "..g_currentMission.missionInfo.displayName);
		local money = g_currentMission.missionInfo.money;
		if money ~= nil then print("Money                 : "..money); end;
		local gameLevel = g_currentMission.missionInfo.economicDifficulty;
		if gameLevel ~= nil then
			print("Economic difficulty   : "..gameLevel);
			print("Sell price multiplier : "..g_currentMission.economyManager.PRICE_MULTIPLIER[gameLevel]);
			print("Buy price multiplier  : "..g_currentMission.economyManager.COST_MULTIPLIER[gameLevel]);
		end;
		local currentDay = g_currentMission.environment.currentDay;
		if currentDay ~= nil then print("Current game day      : "..currentDay); end;
		local hour = g_currentMission.environment.currentHour;
		local minute = g_currentMission.environment.currentMinute;
		if hour ~= nil or minute ~= nil then print("Time of day           : "..hour..":"..minute); end;
		print(" ");

		print("Mean land purchase price = "..g_farmlandManager.pricePerHa.." "..currency.."/ha");
		print("Mean land rent price = "..RN.rentPricePerHa.." "..currency.."/ha");
		for k,v in pairs (g_fieldManager.farmlandIdFieldMapping) do
			for j,field in pairs (v) do
					farmland = field.farmland;
					farmlandId = farmland.id;
					farmlandArea = farmland.areaInHa;
					farmlandPrice = farmland.price;
					farmlandIsOwned = farmland.isOwned;
					if farmlandIsOwned then
						if RN.fieldStatus[farmlandId] == " For sale" then RN.fieldStatus[farmlandId] = " Owned   "; end;
						if RN.fieldStatus[farmlandId] == " For rent" then RN.fieldStatus[farmlandId] = " Rented  "; end;
					end;
			end;
			myPrintFieldInfo5(farmlandId, farmlandArea,  farmlandPrice, currency, RN.fieldStatus[farmlandId]);
			for j,field in pairs (v) do
				fieldId = field.fieldId;
				fieldArea = field.fieldArea;
				fruitTypeIndex = field.fruitType;
				if fruitTypeIndex == nil then
					fruitName = "Undefined";
				else
					fruitType = g_fruitTypeManager:getFruitTypeByIndex(fruitTypeIndex);
					fruitName = fruitType.name;
				end;
				myPrintFieldInfo6(fieldId, fieldArea, fruitName);
			end;
		end;
	end;
end;

function RealNumbersFarmland:update(dt)
end;
function RealNumbersFarmland:draw()
end;
function RealNumbersFarmland:deleteMap()
end;
function RealNumbersFarmland:mouseEvent(posX, posY, isDown, isUp, button)
end;

addModEventListener(RealNumbersFarmland);
