Code: Select all
Roue = {};
function Roue.prerequisitesPresent(specializations)
return true;
end;
function Roue:load(xmlFile)
self.changeSteer = SpecializationUtil.callSpecializationsFunction("changeSteer");
self.changeWheel =0;
self.drivingDir = 1;
end;
function Roue:loadFromAttributesAndNodes(xmlFile, key, resetVehicles)
-- if not resetVehicles then
-- self.changeWheel = Utils.getNoNil(getXMLFloat(xmlFile, key.."#steermode"),0);
-- end;
-- return BaseMission.VEHICLE_LOAD_OK;
end;
function Roue:getSaveAttributesAndNodes(nodeIdent)
-- local attributes = ' steermode="'..tonumber(self.changeWheel)..'"';
-- return attributes, nil;
end;
function Roue:mouseEvent(posX, posY, isDown, isUp, button)
end;
function Roue:keyEvent(unicode, sym, modifier, isDown)
end;
function Roue:update(dt)
if InputBinding.hasEvent(InputBinding.lenkart) and self:getIsActiveForInput() then
self.changeWheel = self.changeWheel +1 ;
RoueEvent.sendEvent(self, self.changeWheel);
end;
if self.changeWheel == 0 then
self:changeSteer(25, -25, 20*self.drivingDir, 25, -25, 20*self.drivingDir, 0, 0, 0, 0, 0, 0)
elseif self.changeWheel == 1 then
self:changeSteer(25, -25, 20*self.drivingDir, 25, -25, 20*self.drivingDir, 10, -10, -8*self.drivingDir, 10, -10, -8*self.drivingDir)
elseif self.changeWheel == 2 then
self.changeWheel = 0;
end;
end;
function Roue:readStream(streamId, connection)
self.changeWheel = streamReadInt8(streamId);
end;
function Roue:writeStream(streamId, connection)
streamWriteInt8(streamId, self.changeWheel);
end;
function Roue:draw()
--g_currentMission:addHelpButtonText(g_i18n:getText("lenkart"), InputBinding.lenkart);
end;
function Roue:changeSteer(wheel1min,wheel1max, wheel1speed, wheel2min, wheel2max,wheel2speed, wheel3min, wheel3max,wheel3speed, wheel4min, wheel4max, wheel4speed)
self.wheels[1].rotMax = Utils.degToRad(wheel1min);
self.wheels[2].rotMax = Utils.degToRad(wheel2min);
self.wheels[1].rotMin = Utils.degToRad(wheel1max);
self.wheels[2].rotMin = Utils.degToRad(wheel2max);
self.wheels[3].rotMax = Utils.degToRad(wheel3min);
self.wheels[4].rotMax = Utils.degToRad(wheel4min);
self.wheels[3].rotMin = Utils.degToRad(wheel3max);
self.wheels[4].rotMin = Utils.degToRad(wheel4max);
self.wheels[1].rotSpeed = Utils.degToRad(wheel1speed);
self.wheels[2].rotSpeed = Utils.degToRad(wheel2speed);
self.wheels[3].rotSpeed = Utils.degToRad(wheel3speed);
self.wheels[4].rotSpeed = Utils.degToRad(wheel4speed);
end;
function Roue:delete()
end;
RoueEvent = {};
RoueEvent_mt = Class(RoueEvent, Event);
InitEventClass(RoueEvent, "RoueEvent");
function RoueEvent:emptyNew()
local self = Event:new(RoueEvent_mt);
self.className="RoueEvent";
return self;
end;
function RoueEvent:new(object, data)
local self = RoueEvent:emptyNew()
self.object = object;
self.data = data;
return self;
end;
function RoueEvent:readStream(streamId, connection)
local id = streamReadInt32(streamId);
self.object = networkGetObject(id);
self.data = streamReadInt8(streamId);
self.object.changeWheel = self.data;
if not connection:getIsServer() then
g_server:broadcastEvent(RoueEvent:new(self.object, self.data), nil, connection, self.object);
end;
end;
function RoueEvent:writeStream(streamId, connection)
streamWriteInt32(streamId, networkGetObjectId(self.object));
streamWriteInt8(streamId, self.data);
end;
function RoueEvent.sendEvent(vehicle, data)
if g_server ~= nil then
g_server:broadcastEvent(RoueEvent:new(vehicle, data), nil, nil, vehicle);
else
g_client:getServerConnection():sendEvent(RoueEvent:new(vehicle, data));
end;
end;