Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Fix AD compatibility #7062 #7066

Merged
merged 1 commit into from
Apr 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions base.lua
Original file line number Diff line number Diff line change
@@ -1363,12 +1363,22 @@ function courseplay:setIsCourseplayDriving(active)
self.cp.isDriving = active
end;

--- Explicit interface function for other mods (like AutoDrive) to start the Courseplay driver (by vehicle:startCpDriver())
function courseplay:startCpDriver()
courseplay.onStartCpAIDriver(self, nil, false, g_currentMission.player.farmId)
end

--- Explicit interface function for other mods (like AutoDrive) to stop the Courseplay driver (by vehicle:stopCpDriver())
function courseplay:stopCpDriver()
courseplay.onStopCpAIDriver(self, AIVehicle.STOP_REASON_REGULAR)
end

--the same code as giants AIVehicle:startAIVehicle(helperIndex, noEventSend, startedFarmId), but customized for cp

--All the code that has to be run on Server and Client from the "start_stop" file has to get in here
function courseplay.onStartCpAIDriver(vehicle,helperIndex,noEventSend, startedFarmId)
local spec = vehicle.spec_aiVehicle
if not vehicle:getIsAIActive() then
if not vehicle:getIsCourseplayDriving() then
--giants code from AIVehicle:startAIVehicle()
courseplay.debugVehicle(courseplay.DBG_AI_DRIVER,vehicle,'Started cp driver, farmID: %s, helperIndex: %s', tostring(startedFarmId),tostring(helperIndex))
if helperIndex ~= nil then
@@ -1437,9 +1447,9 @@ end
--the same code as giants AIVehicle:stopAIVehicle(helperIndex, noEventSend, startedFarmId), but customized for cp

--All the code that has to be run on Server and Client from the "start_stop" file has to get in here
function courseplay.onStopCpAIDriver(vehicle,reason,noEventSend)
function courseplay.onStopCpAIDriver(vehicle, reason, noEventSend)
local spec = vehicle.spec_aiVehicle
if vehicle:getIsAIActive() then
if vehicle:getIsCourseplayDriving() then
--giants code from AIVehicle:stopAIVehicle()
courseplay.debugVehicle(courseplay.DBG_AI_DRIVER,vehicle,'Stopped cp driver')
if noEventSend == nil or noEventSend == false then
5 changes: 5 additions & 0 deletions register.lua
Original file line number Diff line number Diff line change
@@ -26,6 +26,11 @@ function courseplay.registerOverwrittenFunctions(vehicleType)
SpecializationUtil.registerOverwrittenFunction(vehicleType, "updateAILowFrequency", AIDriver.updateAILowFrequency)
end

-- Register interface functions to start/stop the Courseplay driver
function courseplay.registerFunctions(vehicleType)
SpecializationUtil.registerFunction(vehicleType, "startCpDriver", courseplay.startCpDriver)
SpecializationUtil.registerFunction(vehicleType, "stopCpDriver", courseplay.stopCpDriver)
end

function courseplay:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection)
--print(string.format("%s: courseplay:onRegisterActionEvents(isActiveForInput(%s) (%s), isActiveForInputIgnoreSelection(%s))",tostring(self:getName()),tostring(isActiveForInput),tostring(self:getIsActiveForInput(true, true)),tostring(isActiveForInputIgnoreSelection)))