-- @author  FIAT80-90DT 
-- @date  	15.11.2011
--
-- ###- ModdingStage - ### - DO NOT EDIT ### --

ChangePlaneEvent = {};
ChangePlaneEvent_mt = Class(ChangePlaneEvent, Event);

InitEventClass(ChangePlaneEvent, "ChangePlaneEvent");

function ChangePlaneEvent:emptyNew()
    local self = Event:new(ChangePlaneEvent_mt);
    self.className="ChangePlaneEvent";
    return self;
end;

function ChangePlaneEvent:new(vehicle, loading)
    local self = ChangePlaneEvent:emptyNew()
    self.vehicle = vehicle;
	self.loading = loading;
    return self;
end;

function ChangePlaneEvent:readStream(streamId, connection)
    local id = streamReadInt32(streamId);
	self.loading = streamReadBool(streamId);
    self.vehicle = networkGetObject(id);
    self:run(connection);
end;

function ChangePlaneEvent:writeStream(streamId, connection)
    streamWriteInt32(streamId, networkGetObjectId(self.vehicle));
	streamWriteBool(streamId, self.loading);
end;

function ChangePlaneEvent:run(connection)
	self.vehicle:changePlane(self.loading, true);
    if not connection:getIsServer() then
        g_server:broadcastEvent(ChangePlaneEvent:new(self.vehicle, self.loading), nil, connection, self.vehicle);
    end;
end;


function ChangePlaneEvent.sendEvent(vehicle, loading, noEventSend)
	if noEventSend == nil or noEventSend == false then
		if g_server ~= nil then
			g_server:broadcastEvent(ChangePlaneEvent:new(vehicle, loading), nil, nil, vehicle);
		else
			g_client:getServerConnection():sendEvent(ChangePlaneEvent:new(vehicle, loading));
		end;
	end;
end;