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

Commit

Permalink
Showing 27 changed files with 434 additions and 181 deletions.
2 changes: 1 addition & 1 deletion AIDriver.lua
Original file line number Diff line number Diff line change
@@ -1639,7 +1639,7 @@ function AIDriver:onDraw()
self.course:draw()
end
if CpManager.isDeveloper and self.pathfinder then
PathfinderUtil.showNodes(self.pathfinder)
--PathfinderUtil.showNodes(self.pathfinder)
end
end
--TODO: do we want to continue using this setter/getter for driveUnloadNow??
88 changes: 68 additions & 20 deletions BunkersiloManager.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
---@class FieldManager
BunkerSiloManager = CpObject()

--for reference look up : "https://gdn.giants-software.com/documentation_scripting_fs19.php?version=script&category=26&class=244"
--mostly : "BunkerSilo:load(id, xmlFile, key)"
--[[
example bunker with only one entrance side
----------------- <-- heightNode (hx,_,hz)
| X X X X X X X | ---
| X X X X X X X | |
| X X X X X X X | |
| X X X X X X X | |
| X X X X X X X | | bunkerLength
| X X X X X X X | |
| X X X X X X X | |
| X X X X X X X | |
| X X X X X X X | |
| X X X X X X X | ---
widthNode --> | | <-- startNode (sx,_,sz)
(wx,_,wz)
|---------------|
bunkerWidth
X = unitArea = unitWidth*unitHeigth
]]--

-- Constructor
function BunkerSiloManager:init()
print("BunkerSiloManager: init()")
@@ -9,42 +35,57 @@ end

g_bunkerSiloManager = BunkerSiloManager()

--createBunkerSiloMap() is not only for bunkerSilo or it dosen't always has the correct bunker setup ..

--width is workWidth of the tool
function BunkerSiloManager:createBunkerSiloMap(vehicle, Silo, width, height)
-- the developer could have added comments explaining what sx/wx/hx is but chose not to do so
-- ignoring his fellow developers ...
local sx,sz = Silo.bunkerSiloArea.sx,Silo.bunkerSiloArea.sz;
local wx,wz = Silo.bunkerSiloArea.wx,Silo.bunkerSiloArea.wz;
local hx,hz = Silo.bunkerSiloArea.hx,Silo.bunkerSiloArea.hz;
local sy = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, sx, 1, sz);
local bunkerWidth = courseplay:distance(sx,sz, wx, wz)

--only for Heaps as this createBunkerSiloMap() also applies to it ..
local sx,sz = Silo.bunkerSiloArea.sx,Silo.bunkerSiloArea.sz; --start BunkerNode
local wx,wz = Silo.bunkerSiloArea.wx,Silo.bunkerSiloArea.wz; --width BunkerNode "x cordinate"
local hx,hz = Silo.bunkerSiloArea.hx,Silo.bunkerSiloArea.hz; --height/"depth" BunkerNode "z cordinate"
local bunkerWidth = courseplay:distance(sx,sz, wx, wz)
local bunkerLength = courseplay:distance(sx,sz, hx, hz)
local sy = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, sx, 1, sz);

-- check the distance from our vehicle either we are comming from the front or back of the silo
local startDistance = courseplay:distanceToPoint(vehicle, sx, sy, sz)
local endDistance = courseplay:distanceToPoint(vehicle, hx, sy, hz)

--correct data for bunkerSilos
--shorten the BunkerArea by 1.0 , as the silo size from Giants tends to be bigger the the actual fillArea
if Silo.bunkerSiloArea.start then
sx, _, sz = localToWorld(Silo.bunkerSiloArea.start,-0.5,0,0) --start BunkerNode
wx, _, wz = localToWorld(Silo.bunkerSiloArea.width,0.5,0,0) --width BunkerNode "x cordinate"
hx, _, hz = localToWorld(Silo.bunkerSiloArea.height,-0.5,0,1) --height/"depth" BunkerNode "z cordinate"
bunkerWidth = calcDistanceFrom(Silo.bunkerSiloArea.start,Silo.bunkerSiloArea.width)-1
bunkerLength = calcDistanceFrom(Silo.bunkerSiloArea.start,Silo.bunkerSiloArea.height)-1
end


local widthDirX,widthDirY,widthDirZ,widthDistance = courseplay:getWorldDirection(sx,sy,sz, wx,sy,wz);
local heightDirX,heightDirY,heightDirZ,heightDistance = courseplay:getWorldDirection(sx,sy,sz, hx,sy,hz);

local widthCount = 0
if width then
courseplay.debugVehicle(10, vehicle, 'Bunker width %.1f, working width %.1f (passed in)', bunkerWidth, width)
widthCount =math.ceil(bunkerWidth/width)
else
courseplay.debugVehicle(10, vehicle, 'Bunker width %.1f, working width %.1f (calculated)', bunkerWidth, vehicle.cp.workWidth)
widthCount =math.ceil(bunkerWidth/vehicle.cp.workWidth)
width = vehicle.cp.workWidth
end

courseplay.debugVehicle(10, vehicle, 'Bunker width %.1f, working width %.1f (passed in)', bunkerWidth, width)
widthCount =math.ceil(bunkerWidth/width)

if vehicle.cp.mode10.leveling and courseplay:isEven(widthCount) then
widthCount = widthCount+1
end

local heightCount = math.ceil(bunkerLength/ width)
local unitWidth = bunkerWidth/widthCount
local unitHeigth = bunkerLength/heightCount
local heightLengthX = (Silo.bunkerSiloArea.hx-Silo.bunkerSiloArea.sx)/heightCount
local heightLengthZ = (Silo.bunkerSiloArea.hz-Silo.bunkerSiloArea.sz)/heightCount
local widthLengthX = (Silo.bunkerSiloArea.wx-Silo.bunkerSiloArea.sx)/widthCount
local widthLengthZ = (Silo.bunkerSiloArea.wz-Silo.bunkerSiloArea.sz)/widthCount

--width/height in 2D(x and z seperated) of silo

local heightLengthX = (hx-sx)/heightCount
local heightLengthZ = (hz-sz)/heightCount
local widthLengthX = (wx-sx)/widthCount
local widthLengthZ = (wz-sz)/widthCount
local getOffTheWall = 0.5;

local lastValidfillType = 0
@@ -56,18 +97,24 @@ function BunkerSiloManager:createBunkerSiloMap(vehicle, Silo, width, height)
local newWz = sz + widthLengthZ
local newHx = sx + heightLengthX
local newHz = sz + heightLengthZ


--herrain height at start of small part
local wY = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, newWx, 1, newWz);
--herrain height at end of small part
local hY = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, newHx, 1, newHz);
--fillType in between
local fillType = DensityMapHeightUtil.getFillTypeAtLine(newWx, wY, newWz, newHx, hY, newHz, 5)
if lastValidfillType ~= fillType and fillType ~= 0 then
lastValidfillType = fillType
end
--fillLevel in small part
local newFillLevel = DensityMapHeightUtil.getFillLevelAtArea(fillType, sx, sz, newWx, newWz, newHx, newHz )
--center probably of small part ??
local bx = sx + (widthLengthX/2) + (heightLengthX/2)
local bz = sz + (widthLengthZ/2) + (heightLengthZ/2)
local offset = 0
if vehicle.cp.mode9TargetSilo and vehicle.cp.mode9TargetSilo.type and vehicle.cp.mode9TargetSilo.type == "heap" then
--no idea ??
offset = unitWidth/2
else
if widthIndex == 1 then
@@ -78,6 +125,7 @@ function BunkerSiloManager:createBunkerSiloMap(vehicle, Silo, width, height)
offset = unitWidth / 2
end
end
-- something with direction ??
local cx,cz = sx +(widthDirX*offset)+(heightLengthX/2),sz +(widthDirZ*offset)+ (heightLengthZ/2)
if vehicle.cp.mode == courseplay.MODE_SHOVEL_FILL_AND_EMPTY and heightIndex == heightCount then
cx,cz = sx +(widthDirX*offset)+(heightLengthX),sz +(widthDirZ*offset)+ (heightLengthZ)
@@ -114,7 +162,7 @@ function BunkerSiloManager:createBunkerSiloMap(vehicle, Silo, width, height)
else
courseplay:debug(('%s: empty Bunkersilo will be devided in %d lines and %d columns'):format(nameNum(vehicle), heightCount, widthCount), 10);
end
--invert table
--invert table as we are comming from the back into the silo
if endDistance < startDistance then
courseplay:debug(('%s: Bunkersilo will be approached from the back -> turn map'):format(nameNum(vehicle)), 10);
local newMap = {}
2 changes: 2 additions & 0 deletions CpManager.lua
Original file line number Diff line number Diff line change
@@ -829,13 +829,15 @@ end;
function CpManager:minuteChanged()
end;

--FieldScan startup dialog and github info
function CpManager:showYesNoDialogue(title, text, callbackFn)
-- don't show anything if the tutorial dialog is open (it takes a while until is isOpen shows true after startup, hence the clock)
--courseplay.debugFormat(12, "clock %d %s", courseplay.clock, tostring(g_gui.guis.YesNoDialog.target and g_gui.guis.YesNoDialog.target.isOpen))
if courseplay.clock < 2000 or (g_gui.guis.YesNoDialog.target and g_gui.guis.YesNoDialog.target.isOpen) then
return
end
--courseplay.debugFormat(12, text)
local text =string.format("%s\n %s",courseplay:loc('COURSEPLAY_YES_NO_FIELDSCAN'),courseplay:loc('COURSEPLAY_SUPPORT_INFO'))
g_gui:showYesNoDialog({text=text, title=title, callback=callbackFn, target=self})
end;

17 changes: 16 additions & 1 deletion DevHelper.lua
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ function DevHelper:update()
end

if self.vehicleData then
self.collisionData = PathfinderUtil.getCollisionData(self.node, self.vehicleData, 'me')
self.collisionData = PathfinderUtil.getBoundingBoxInWorldCoordinates(self.node, self.vehicleData, 'me')
hasCollision, vehicle = PathfinderUtil.findCollidingVehicles(
self.collisionData,
self.node,
@@ -210,6 +210,7 @@ function DevHelper:draw()
end
end
PathfinderUtil.showNodes(self.pathfinder)
PathfinderUtil.showOverlapBoxes()
end

---@param path State3D[]
@@ -273,6 +274,20 @@ function DevHelper:showVehicleSize()
drawDebugLine(x2,y2,z2,0,0,1,x4,y4,z4,0,0,1);
drawDebugLine(x3,y3,z3,0,0,1,x4,y4,z4,0,0,1);
end
if self.vehicleData.trailerRectangle then
local x, y, z = localToWorld(g_devHelper.helperNode, 0, 0, self.vehicleData.trailerHitchOffset)
setTranslation(g_devHelper.helperNode, x, y, z)
setRotation(g_devHelper.helperNode, 0, courseGenerator.toCpAngle(node.tTrailer), 0)
local x1,y1,z1 = localToWorld(g_devHelper.helperNode, self.vehicleData.trailerRectangle.dRight, 2, self.vehicleData.trailerRectangle.dFront);
local x2,y2,z2 = localToWorld(g_devHelper.helperNode, self.vehicleData.trailerRectangle.dLeft, 2, self.vehicleData.trailerRectangle.dFront);
local x3,y3,z3 = localToWorld(g_devHelper.helperNode, self.vehicleData.trailerRectangle.dRight, 2, self.vehicleData.trailerRectangle.dRear);
local x4,y4,z4 = localToWorld(g_devHelper.helperNode, self.vehicleData.trailerRectangle.dLeft, 2, self.vehicleData.trailerRectangle.dRear);

drawDebugLine(x1,y1,z1,0,1,0,x2,y2,z2,0,1,0);
drawDebugLine(x1,y1,z1,0,1,0,x3,y3,z3,0,1,0);
drawDebugLine(x2,y2,z2,0,1,0,x4,y4,z4,0,1,0);
drawDebugLine(x3,y3,z3,0,1,0,x4,y4,z4,0,1,0);
end
end
if self.collisionData then
for i = 1, 4 do
Loading

0 comments on commit e61a0b6

Please sign in to comment.