newExhaustEffects = {};

function newExhaustEffects.prerequisitesPresent(specializations)
    return true;
end;
function newExhaustEffects.registerEventListeners(vehicleType)
	local functionNames = { "onLoad", "onUpdate", "onDelete", "onLeaveVehicle" }

	for i, v in ipairs(functionNames) do
		SpecializationUtil.registerEventListener(vehicleType, v, newExhaustEffects)
	end
end
function newExhaustEffects:onLoad(savegame)
	self.nrep = {};  
	self.nrep.psThreshold = Utils.getNoNil(getXMLFloat(self.xmlFile, "vehicle.motorized.newExhaustEffects.newExhaustEffect#psThreshold"), 0.85);
	self.nrep.ps = {};
	ParticleUtil.loadParticleSystem(self.xmlFile, self.nrep.ps, "vehicle.motorized.newExhaustEffects.newExhaustEffect", self.components, false, nil, self.baseDirectory)
end;
function newExhaustEffects:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
	
	if self:getIsActive() and self.spec_motorized.isMotorStarted  then		
		local mLoad =  self.spec_motorized.motor:getMotorAppliedTorque() / math.max(self.spec_motorized.motor:getMotorAvailableTorque(), 0.0001)
		if mLoad > self.nrep.psThreshold then
			ParticleUtil.setEmittingState(self.nrep.ps, true);
		else
			ParticleUtil.setEmittingState(self.nrep.ps, false)
		end;
	end;
end;
function newExhaustEffects:onDelete()
	if self.nrep.ps ~= nil then
		ParticleUtil.deleteParticleSystem(self.nrep.ps);
	end;
end;
function newExhaustEffects:onLeaveVehicle()
	if self.nrep.ps then
		ParticleUtil.setEmittingState(self.nrep.ps, false);
	end;
end;