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

Update to latest version #3

Merged
merged 15 commits into from
Feb 26, 2013
Merged
Show file tree
Hide file tree
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: 10 additions & 6 deletions base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ function courseplay:onEnter()
if self.mouse_enabled then
InputBinding.setShowMouseCursor(true);
end

if self.drive and self.steeringEnabled then
self.steeringEnabled = false
end
end

-- displays help text, user_input
Expand Down Expand Up @@ -636,9 +640,9 @@ function courseplay:readStream(streamId, connection)
self.forced_to_stop = streamDebugReadBool(streamId)
self.global_info_text = streamDebugReadString(streamId)
self.info_text = streamDebugReadString(streamId)
self.lastTrailerToFillDistance = streamDebugReadFloat32(streamId)
self.last_fill_level = streamDebugReadInt32(streamId)
self.loopCounter = streamDebugReadInt32(streamId)
self.lastTrailerToFillDistance = streamDebugReadFloat32(streamId)
self.loaded = streamDebugReadBool(streamId)
self.max_speed = streamDebugReadFloat32(streamId)
self.mouse_enabled = streamDebugReadBool(streamId)
self.mouse_right_key_enabled = streamDebugReadBool(streamId)
Expand All @@ -653,8 +657,8 @@ function courseplay:readStream(streamId, connection)
self.selected_combine_number = streamDebugReadInt32(streamId)
self.selected_course_number = streamDebugReadInt32(streamId)
self.shortest_dist = streamDebugReadFloat32(streamId) -- 20.
self.showHudInfoBase = streamDebugReadInt32(streamId)
self.show_hud = streamDebugReadBool(streamId)
self.showHudInfoBase = streamDebugReadInt32(streamId)
self.sl = streamDebugReadInt32(streamId)
self.startWork = streamDebugReadInt32(streamId)
self.stopWork = streamDebugReadInt32(streamId)
Expand All @@ -667,15 +671,15 @@ function courseplay:readStream(streamId, connection)
self.tipper_offset = streamDebugReadFloat32(streamId)
self.tipRefOffset = streamDebugReadFloat32(streamId)
self.tmr = streamDebugReadInt32(streamId)
self.turnRadiusAutoMode = streamDebugReadBool(streamId);
self.turn_radius = streamDebugReadFloat32(streamId)
self.turn_speed = streamDebugReadFloat32(streamId)
self.unloaded = streamDebugReadBool(streamId) -- 40.
self.turnRadiusAutoMode = streamDebugReadBool(streamId);
self.unload_speed = streamDebugReadFloat32(streamId)
self.unloaded = streamDebugReadBool(streamId) -- 40.
self.use_speed = streamDebugReadBool(streamId)
self.user_input = streamDebugReadString(streamId)
self.user_input_active = streamDebugReadBool(streamId)
self.user_input_message = streamDebugReadString(streamId)
self.use_speed = streamDebugReadBool(streamId)
self.wait = streamDebugReadBool(streamId)
self.waitPoints = streamDebugReadInt32(streamId)
self.waitTime = streamDebugReadInt32(streamId)
Expand Down
98 changes: 0 additions & 98 deletions courseplay_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,104 +147,6 @@ end

stream_debug_counter = 0

function streamDebugWriteFloat32(streamId, value)
value = Utils.getNoNil(value, 0.0)
stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
--courseplay:debug("float: ")
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
streamWriteFloat32(streamId, value)
end

function streamDebugWriteBool(streamId, value)
value = Utils.getNoNil(value, false)
if value == 1 then
value = true
end

if value == 0 then
value = false
end

stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
--courseplay:debug("Bool: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
streamWriteBool(streamId, value)
end

function streamDebugWriteInt32(streamId, value)
value = Utils.getNoNil(value, 0)
stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
--courseplay:debug("Int32: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
streamWriteInt32(streamId, value)
end

function streamDebugWriteString(streamId, value)
value = Utils.getNoNil(value, "")
stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
--courseplay:debug("String: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
streamWriteString(streamId, value)
end


function streamDebugReadFloat32(streamId)
stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
local value = streamReadFloat32(streamId)
--courseplay:debug("Float32: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
return value
end


function streamDebugReadInt32(streamId)
stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
local value = streamReadInt32(streamId)
--courseplay:debug("Int32: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
return value
end

function streamDebugReadBool(streamId)
stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
local value = streamReadBool(streamId)
--courseplay:debug("Bool: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
return value
end

function streamDebugReadString(streamId)
stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
local value = streamReadString(streamId)
--courseplay:debug("String: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
return value
end

addModEventListener(courseplay_manager);

--
Expand Down
80 changes: 40 additions & 40 deletions debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ stream_debug_counter = 0
function streamDebugWriteFloat32(streamId, value)
value = Utils.getNoNil(value, 0.0)
stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
--courseplay:debug("float: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
courseplay:debug("++++++++++++++++", 4)
courseplay:debug(stream_debug_counter, 4)
courseplay:debug("float: ", 4)
courseplay:debug(value, 4)
courseplay:debug("-----------------", 4)
streamWriteFloat32(streamId, value)
end

Expand All @@ -127,78 +127,78 @@ function streamDebugWriteBool(streamId, value)
end

stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
--courseplay:debug("Bool: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
courseplay:debug("++++++++++++++++", 4)
courseplay:debug(stream_debug_counter, 4)
courseplay:debug("Bool: ", 4)
courseplay:debug(value, 4)
courseplay:debug("-----------------", 4)
streamWriteBool(streamId, value)
end

function streamDebugWriteInt32(streamId, value)
value = Utils.getNoNil(value, 0)
stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
--courseplay:debug("Int32: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
courseplay:debug("++++++++++++++++", 4)
courseplay:debug(stream_debug_counter, 4)
courseplay:debug("Int32: ", 4)
courseplay:debug(value, 4)
courseplay:debug("-----------------", 4)
streamWriteInt32(streamId, value)
end

function streamDebugWriteString(streamId, value)
value = Utils.getNoNil(value, "")
stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
--courseplay:debug("String: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
courseplay:debug("++++++++++++++++", 4)
courseplay:debug(stream_debug_counter, 4)
courseplay:debug("String: ", 4)
courseplay:debug(value, 4)
courseplay:debug("-----------------", 4)
streamWriteString(streamId, value)
end


function streamDebugReadFloat32(streamId)
stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
courseplay:debug("++++++++++++++++", 4)
courseplay:debug(stream_debug_counter, 4)
local value = streamReadFloat32(streamId)
--courseplay:debug("Float32: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
courseplay:debug("Float32: ", 4)
courseplay:debug(value, 4)
courseplay:debug("-----------------", 4)
return value
end


function streamDebugReadInt32(streamId)
stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
courseplay:debug("++++++++++++++++", 4)
courseplay:debug(stream_debug_counter, 4)
local value = streamReadInt32(streamId)
--courseplay:debug("Int32: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
courseplay:debug("Int32: ", 4)
courseplay:debug(value, 4)
courseplay:debug("-----------------", 4)
return value
end

function streamDebugReadBool(streamId)
stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
courseplay:debug("++++++++++++++++", 4)
courseplay:debug(stream_debug_counter, 4)
local value = streamReadBool(streamId, 4)
--courseplay:debug("Bool: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
courseplay:debug("Bool: ", 4)
courseplay:debug(value, 4)
courseplay:debug("-----------------", 4)
return value
end

function streamDebugReadString(streamId)
stream_debug_counter = stream_debug_counter + 1
--courseplay:debug("++++++++++++++++", 4)
--courseplay:debug(stream_debug_counter, 4)
courseplay:debug("++++++++++++++++", 4)
courseplay:debug(stream_debug_counter, 4)
local value = streamReadString(streamId)
--courseplay:debug("String: ", 4)
--courseplay:debug(value, 4)
--courseplay:debug("-----------------", 4)
courseplay:debug("String: ", 4)
courseplay:debug(value, 4)
courseplay:debug("-----------------", 4)
return value
end
41 changes: 21 additions & 20 deletions drive.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ function courseplay:drive(self, dt)

self.dist = courseplay:distance(cx, cz, ctx, ctz)
--courseplay:debug(string.format("Tx: %f2 Tz: %f2 WPcx: %f2 WPcz: %f2 dist: %f2 ", ctx, ctz, cx, cz, self.dist ), 2)
local fwd = nil
local distToChange = nil
local lx, lz = AIVehicleUtil.getDriveDirection(self.rootNode, cx, cty, cz);

-- what about our tippers?
local tipper_fill_level, tipper_capacity = self:getAttachedTrailersFillLevelAndCapacity()
local fill_level = nil
Expand Down Expand Up @@ -430,9 +434,12 @@ function courseplay:drive(self, dt)
allowedToDrive, workArea, workSpeed = courseplay:handle_mode4(self, allowedToDrive, workArea, workSpeed, fill_level, last_recordnumber)
end




-- Mode 6 Fieldwork for balers and foragewagon
if self.ai_mode == 6 and self.startWork ~= nil and self.stopWork ~= nil then
allowedToDrive, workArea, workSpeed, active_tipper = courseplay:handle_mode6(self, allowedToDrive, workArea, workSpeed, fill_level, last_recordnumber)
allowedToDrive, workArea, workSpeed, active_tipper = courseplay:handle_mode6(self, allowedToDrive, workArea, workSpeed, fill_level, last_recordnumber, lx , lz )
if not workArea and self.aiTrafficCollisionTrigger ~= nil and self.grainTankCapacity == nil then
-- is there a tipTrigger within 10 meters?

Expand Down Expand Up @@ -525,8 +532,6 @@ function courseplay:drive(self, dt)
if allowedToDrive then
if (self.lastSpeed*3600) - (vehicle_in_front.lastSpeedReal*3600) > 15 then
self.cpTrafficBrake = true
elseif vehicle_in_front.rootNode ~= nil and vehicle_in_front.lastSpeed ~= nil and courseplay:distance_to_object(self, vehicle_in_front) < 3 then
refSpeed = math.min(vehicle_in_front.lastSpeedReal -(3*3600),refSpeed)
else
refSpeed = math.min(vehicle_in_front.lastSpeedReal,refSpeed)
end
Expand Down Expand Up @@ -573,12 +578,8 @@ function courseplay:drive(self, dt)
if self.ESLimiter ~= nil and self.ESLimiter.maxRPM[5] == nil then
self.info_text = courseplay:get_locale(self, "CPWrongESLversion")
end

-- where to drive?
local fwd = nil
local distToChange = nil
local lx, lz = AIVehicleUtil.getDriveDirection(self.rootNode, cx, cty, cz);

-- where to drive?
if self.Waypoints[self.recordnumber].rev then
lz = lz * -1
lx = lx * -1
Expand All @@ -592,28 +593,29 @@ function courseplay:drive(self, dt)
end

-- go, go, go!
if self.recordnumber == 1 then --courtesy of Thomas Gärtner
if self.recordnumber == 1 or self.recordnumber == self.maxnumber - 1 then
distToChange = 0.5
elseif self.recordnumber + 1 <= self.maxnumber then
local beforeReverse = (self.Waypoints[self.recordnumber + 1].rev and (self.Waypoints[self.recordnumber].rev == false))
local afterReverse = (not self.Waypoints[self.recordnumber + 1].rev and self.Waypoints[last_recordnumber].rev)
if (self.Waypoints[self.recordnumber].wait or beforeReverse) and self.Waypoints[self.recordnumber].rev == false then -- or afterReverse or self.recordnumber == 1
distToChange = 1
elseif self.Waypoints[self.recordnumber].rev and self.Waypoints[self.recordnumber].wait or afterReverse then
elseif (self.Waypoints[self.recordnumber].rev and self.Waypoints[self.recordnumber].wait) or afterReverse then
distToChange = 2
elseif self.Waypoints[self.recordnumber].rev then
distToChange = 6
-- elseif self.ai_mode == 7 and (self.recordnumber > (self.maxnumber-3)) then
-- distToChange = 2
distToChange = 1;
elseif self.ai_mode == 4 or self.ai_mode == 6 then
distToChange = 5;
elseif self.ai_mode == 7 and (self.recordnumber > (self.maxnumber-3)) then
distToChange = 2

else
distToChange = 5
end
distToChange = 2.85; --orig: 5
end;
else
distToChange = 5
distToChange = 2.85; --orig: 5
end


-- record shortest distance to the next waypoint
if self.shortest_dist == nil or self.shortest_dist > self.dist then
self.shortest_dist = self.dist
Expand Down Expand Up @@ -674,7 +676,7 @@ function courseplay:set_traffc_collision(self, lx, lz)
colDirZ = 0.4;
end;
--courseplay:debug(string.format("colDirX: %f colDirZ %f ",colDirX,colDirZ ), 2)

if CPDebugLevel > 0 then
local x,y,z = getWorldTranslation(self.aiTrafficCollisionTrigger)
local x1,y1,z1 = localToWorld(self.aiTrafficCollisionTrigger, colDirX*5, 0, colDirZ*5 )
Expand Down Expand Up @@ -813,8 +815,7 @@ function courseplay:openCloseCover(self)
local tIdx = self.cp.tippersWithCovers[i];
local tipper = self.tippers[tIdx];

--courseplay:debug(self.name .. ": tipper w/ cover = " .. tostring(tipper.name), 3);

--INFO: setPlane(true) = open / setPlane(false) = closed
if tipper.plane.bOpen ~= nil and (self.ai_mode == 1 or self.ai_mode == 2 or self.ai_mode == 5) then
--courseplay:debug(string.format("recordnumber=%s, maxnumber=%s, currentTipTrigger=%s, plane.bOpen=%s", tostring(self.recordnumber), tostring(self.maxnumber), tostring(self.currentTipTrigger ~= nil), tostring(tipper.plane.bOpen)), 3);
local minCoverWaypoint = 3;
Expand Down
Loading