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

--[[
	Added with version 1.1.0.0
	This script changes the lifetime and maintenance inverval parameters of vehices and equipment
	Daily upkeep can also be changed.
	Parameter values are defined in RealNumbersInitialization.lua
--]]

RealNumbersVehicleMaintenance = {};


function RealNumbersVehicleMaintenance:loadMap(name)
	local isDebug = RN.isDebug;
	RN.VehicleMaintenanceHasNotRun = true;
	if isDebug then print("\nFS19_RealLifeNumbers: RealNumbersVehicleMaintenance Active, press lAlt-rm \n") end;
end;

function RealNumbersVehicleMaintenance:keyEvent(unicode, sym, modifier, isDown)
	if Input.isKeyPressed(Input.KEY_lalt) and Input.isKeyPressed(Input.KEY_m) and Input.isKeyPressed(Input.KEY_m) then
		if g_storeManager.items ~= nil then
			for k,items in pairs(g_storeManager.items) do
				local name = tostring(items.categoryName);
				if RN.lifeTime[name] ~= nil then
					items.lifetime = RN.lifeTime[name];
				end;
				if RN.dailyUpkeep[name] ~= nil then
					items.dailyUpkeep = RN.dailyUpkeep[name];
				end;
			end;	
		end;
		
		print("\nlAlt-rm pressed\n");
		print("Modified service intervals for vehicles and equipment");
		print(" ");
	
		if g_currentMission.vehicles  ~= nil then
			for k,vehicle in pairs(g_currentMission.vehicles) do
				if vehicle.spec_wearable ~= nil then
					local name = tostring(vehicle.typeName);
					vehicle.spec_wearable.wearDuration = RN.wearDuration;
					vehicle.spec_wearable.fieldMultiplier = RN.fieldMultiplier;
					vehicle.spec_wearable.workMultiplier = RN.workMultiplier;
					print("Service interval: vehicle "..k.." : "..name.." : "..RN.vehicleServiceInterval.." hours");

				end;
			end;
			print(" ");
		end;
	end;
end;
function RealNumbersVehicleMaintenance:update(dt)

		if g_storeManager.items ~= nil then
			for k,items in pairs(g_storeManager.items) do
				local name = tostring(items.categoryName);
				if RN.lifeTime[name] ~= nil then
					items.lifetime = RN.lifeTime[name];
				end;
				if RN.dailyUpkeep[name] ~= nil then
					items.dailyUpkeep = RN.dailyUpkeep[name];
				end;
			end;	
		end;

		if g_currentMission.vehicles  ~= nil then
			for k,vehicle in pairs(g_currentMission.vehicles) do
				if vehicle.spec_wearable ~= nil then
					local name = tostring(vehicle.typeName);
					vehicle.spec_wearable.wearDuration = RN.wearDuration;
					vehicle.spec_wearable.fieldMultiplier = RN.fieldMultiplier;
					vehicle.spec_wearable.workMultiplier = RN.workMultiplier;
--					print("Service interval: vehicle "..k.." : "..name.." : "..RN.vehicleServiceInterval.." hours");

				end;
			end;	
		end;
end;
function RealNumbersVehicleMaintenance:draw()
end;
function RealNumbersVehicleMaintenance:deleteMap()
end;
function RealNumbersVehicleMaintenance:mouseEvent(posX, posY, isDown, isUp, button)
end;

addModEventListener(RealNumbersVehicleMaintenance);