variableSpondine = {};
function variableSpondine.prerequisitesPresent(specializations) return SpecializationUtil.hasSpecialization(Attachable, specializations) and SpecializationUtil.hasSpecialization(Fillable, specializations) end;
function variableSpondine:load(xmlFile)
	self.setcurrentSpondine = SpecializationUtil.callSpecializationsFunction("setcurrentSpondine"); self.currentSpondine = 1;
	self.spondine = {};	self.spondine.nodes = {}; local i = 0; local j = 0;	while true do
	local path = string.format("vehicle.variableSpondine.node(%d)", i);
	local name = getXMLString(xmlFile, path .. "#name"); if name == nil then break; end; local capacity = getXMLInt(xmlFile, path .. "#capacity");
	local fillTypes = {}; local fruitTypes = getXMLString(xmlFile, path .. "#fruitTypes"); local types = Utils.splitString(" ", fruitTypes);
	for k,v in pairs(types) do local fillType = Fillable.fillTypeNameToInt[v]; if fillType ~= nil then fillTypes[fillType] = true; end;	end;
	local parts = {}; j = 0; local k = 1;
	local str = getXMLString(xmlFile, string.format("vehicle.variableSpondine.node(%d).part(%d)#index%d", i, j, k));
	while str ~= nil do	local subparts = {}; subparts.objects = {}; while str ~= nil do local tmpIdx = Utils.indexToObject(self.components, str)
		k = k + 1;	table.insert(subparts.objects, tmpIdx);	str = getXMLString(xmlFile, string.format("vehicle.variableSpondine.node(%d).part(%d)#index%d", i, j, k)); end;
		subparts.subPartCount = k - 1;	if subparts ~= nil then	table.insert(parts, subparts); else break;	end;
		j = j + 1; k = 1; str = getXMLString(xmlFile, string.format("vehicle.variableSpondine.node(%d).part(%d)#index%d", i, j, k)); end;
	local entry={};	entry.name = name; entry.capacity = capacity; entry.index = index; entry.parts = parts; entry.fillTypes = fillTypes; table.insert(self.spondine.nodes, entry);	i = i + 1; end; self.isReset = false; end;
function variableSpondine:delete() end;
function variableSpondine:readStream(streamId, connection) self:setcurrentSpondine(streamReadInt8(streamId), true); end;
function variableSpondine:writeStream(streamId, connection)	streamWriteInt8(streamId, self.currentSpondine); end;
function variableSpondine:setcurrentSpondine(int, noEventSend) self.currentSpondine = int; setcurrentSpondineEvent.sendEvent(self, int, noEventSend); end;
function variableSpondine:loadFromAttributesAndNodes(xmlFile, key, resetVehicles) local currentSpondine = getXMLInt(xmlFile, key .. "#currentSpondine"); if currentSpondine ~= nil then self:setcurrentSpondine(currentSpondine-1); end;
	return BaseMission.VEHICLE_LOAD_OK; end;
function variableSpondine:getSaveAttributesAndNodes(nodeIdent) local attributes = 'currentSpondine="' .. self.currentSpondine .. '"'; return attributes; end;
function variableSpondine:mouseEvent(posX, posY, isDown, isUp, button) end;
function variableSpondine:keyEvent(unicode, sym, modifier, isDown) end;
function variableSpondine:update(dt) if g_currentMission.player ~= nil and g_currentMission.player.isEntered then
	local px, py, pz = getWorldTranslation(g_currentMission.player.rootNode); local tx, ty, tz = getWorldTranslation(self.components[1].node);
	if Utils.vector3Length(px-tx, py-ty, pz-tz) < 3 then if self.fillLevel == 0 and InputBinding.hasEvent(InputBinding.change) then	if self.currentSpondine == 1 then self:setcurrentSpondine(2); elseif self.currentSpondine == 3 then self:setcurrentSpondine(0); end; end;
	if self.fillLevel == 0 then if self.currentSpondine == 1 then g_currentMission:addHelpButtonText(string.format(g_i18n:getText("variableSpondine_NoGrain"), self.typeDesc), InputBinding.change); else g_currentMission:addHelpButtonText(string.format(g_i18n:getText("variableSpondine_Grain") , self.typeDesc), InputBinding.change); end; end;
	if self.fillLevel > 0 then g_currentMission:addExtraPrintText(g_i18n:getText("spondineOff")); end; end; end; end;
function variableSpondine:updateTick(dt)
	if self.currentSpondine == 0 then self:playAnimation("spondineCollisione", -1); self.currentSpondine = 1;	for i=1, table.getn(self.spondine.nodes) do	for j=1, table.getn(self.spondine.nodes[i].parts) do if i ~= self.currentSpondine 
		then for k=1,table.getn(self.spondine.nodes[i].parts[j].objects) do setVisibility(self.spondine.nodes[i].parts[j].objects[k], false); end; 
		else for k=1,table.getn(self.spondine.nodes[i].parts[j].objects) do	setVisibility(self.spondine.nodes[i].parts[j].objects[k], true); end; end; end; end;
		for i,j in pairs(self.fillTypes) do	if self.spondine.nodes[self.currentSpondine].fillTypes[i] == true then self.fillTypes[i] = true; else self.fillTypes[i] = false; end; end;
		self.capacity = self.spondine.nodes[self.currentSpondine].capacity;	self:setFillLevel(self.fillLevel, self.currentFillType);
	elseif self.currentSpondine == 2 then self:playAnimation("spondineCollisione", 1); self.currentSpondine = 3; for i=1, table.getn(self.spondine.nodes) do	for j=1, table.getn(self.spondine.nodes[i].parts) do if i ~= self.currentSpondine-1 
		then for k=1,table.getn(self.spondine.nodes[i].parts[j].objects) do	setVisibility(self.spondine.nodes[i].parts[j].objects[k], false); end;
		else for k=1,table.getn(self.spondine.nodes[i].parts[j].objects) do	setVisibility(self.spondine.nodes[i].parts[j].objects[k], true); end; end; end; end;
		for i,j in pairs(self.fillTypes) do	if self.spondine.nodes[self.currentSpondine-1].fillTypes[i] == true then self.fillTypes[i] = true; else self.fillTypes[i] = false; end;	end;
		self.capacity = self.spondine.nodes[self.currentSpondine-1].capacity; self:getFirstEnabledFillType(); end;
	if self.isReset == false then self:setcurrentSpondine(self.currentSpondine-1); self.isReset = true; end; end;
function variableSpondine:draw() end;
function variableSpondine:onAttach(attacherVehicle) end;
function variableSpondine:onDetach() end;
setcurrentSpondineEvent = {}; setcurrentSpondineEvent_mt = Class(setcurrentSpondineEvent, Event); InitEventClass(setcurrentSpondineEvent, "setcurrentSpondineEvent");
function setcurrentSpondineEvent:emptyNew() local self = Event:new(setcurrentSpondineEvent_mt); self.className="setcurrentSpondineEvent"; return self; end;
function setcurrentSpondineEvent:new(vehicle, currentSpondine) local self = setcurrentSpondineEvent:emptyNew() self.vehicle = vehicle; self.currentSpondine = currentSpondine; return self; end;
function setcurrentSpondineEvent:readStream(streamId, connection) local id = streamReadInt32(streamId); self.vehicle = networkGetObject(id);  
self.currentSpondine = streamReadInt8(streamId); self.vehicle:setcurrentSpondine(self.currentSpondine, true);
	if not connection:getIsServer() then g_server:broadcastEvent(setcurrentSpondineEvent:new(self.vehicle, self.currentSpondine), nil, connection, self.vehicle); end; end;
function setcurrentSpondineEvent:writeStream(streamId, connection) streamWriteInt32(streamId, networkGetObjectId(self.vehicle)); streamWriteInt8(streamId, self.currentSpondine); end;
function setcurrentSpondineEvent.sendEvent(vehicle, currentSpondine, noEventSend) if noEventSend == nil or noEventSend == false then
	if g_server ~= nil then	g_server:broadcastEvent(setcurrentSpondineEvent:new(vehicle, currentSpondine), nil, nil, vehicle);
	else g_client:getServerConnection():sendEvent(setcurrentSpondineEvent:new(vehicle, currentSpondine)); end; end; end;