Difference between revisions of "MIST hex aStar"
From DCS World Wiki - Hoggitworld.com
(Created page with "{{Mission Scripting |fName= mist.hex.aStar| |vNum = Mist 4.6 |desc= Uses the A* algorithm to calculate the shortest path between a start point hexA and the destination of h...") |
|||
| Line 6: | Line 6: | ||
|desc= Uses the A* algorithm to calculate the shortest path between a start point hexA and the destination of hexB given anything blocking the route as defined by blockers. | |desc= Uses the A* algorithm to calculate the shortest path between a start point hexA and the destination of hexB given anything blocking the route as defined by blockers. | ||
| + | |||
| + | I would recommend running mist.lineSimplify() on the resulting path to smooth it out. | ||
|rtnType= table | |rtnType= table | ||
| Line 55: | Line 57: | ||
</code> | </code> | ||
| − | |notes= | + | |notes= As written this function is most optimized for finding a route for ship groups in DCS. Ship AI in DCS does not know how to route around islands and unless the game adds something cool like a destroyer that sprouts giant mech legs to walks on land we are forced to make the AI navigate around obstacles. It can be useful for aircraft, but that is only assuming you want to 100% block off a certain areas of the map to force the AI to fly around. |
| + | |||
| + | To be honest it was easier to create this basic version and give explicit permission to copy and modify the function for your own uses. All one simply needs to do is to modify how "cost" is calculated. You could have a modifier for friendly vs enemy territory, or apply a threat score based on sams to route around danger. Your imagination is the limit. | ||
| + | |||
| + | |||
|funcs= {{listOfMistHexFuncs}} | |funcs= {{listOfMistHexFuncs}} | ||
Latest revision as of 23:19, 8 September 2026
mist.hex.aStar
| Added with: Mist 4.6 |
| Description |
| Uses the A* algorithm to calculate the shortest path between a start point hexA and the destination of hexB given anything blocking the route as defined by blockers.
I would recommend running mist.lineSimplify() on the resulting path to smooth it out. |
| Syntax |
| table mist.hex.aStar(table hexA ,table hexB , table blockers ) |
| Valid Input Values: |
| {q = 4, r = 2, s = -6}
hash: "2 4 -6" |
| Return value: |
| table |
| Return example: |
| Usage Examples: |
| The following will draw on the map the path generated between the trigger zones "start" and "dest". Two group's routes are being used to define islands that must be routed around.
local avoid = {mist.hex.getFromRoute(mist.getGroupPoints("island1")), mist.hex.getFromRoute(mist.getGroupPoints("island2"))}
local mergedBlockers = {}
for i = 1, #avoid do -- need to merge
for hexName, hexVal in pairs(avoid[i]) do
mergedBlockers[hexName] = hexVal
end
end
local startHex = mist.hex.pointToHex(trigger.misc.getZone("start").point)
local destHex = mist.hex.pointToHex(trigger.misc.getZone("dest").point)
local path = mist.hex.aStar(startHex, destHex, mergedBlockers)
if type(path) == "table" then
for i = 1, #path-1 do
mist.marker.add({mType = "arrow", color = {0, 0, 1, 0.5}, lineType = 1, points = {path[i+1], path[i]},})
end
end
|
| Notes: |
| As written this function is most optimized for finding a route for ship groups in DCS. Ship AI in DCS does not know how to route around islands and unless the game adds something cool like a destroyer that sprouts giant mech legs to walks on land we are forced to make the AI navigate around obstacles. It can be useful for aircraft, but that is only assuming you want to 100% block off a certain areas of the map to force the AI to fly around.
To be honest it was easier to create this basic version and give explicit permission to copy and modify the function for your own uses. All one simply needs to do is to modify how "cost" is calculated. You could have a modifier for friendly vs enemy territory, or apply a threat score based on sams to route around danger. Your imagination is the limit. |
| Related Functions |
| to, getRadius, setRadius, add, subtract,scale, rotate_left, rotate_right, neighbor, getNeighborCount, diagonalNeighbor, length, distance, round, lerp, cubeScale, cubeRing, cubeSpiral, lineDraw, cubeToAxial, axialToCube, pointToHex, makeVek2, makeVec3, makeVec3GL, hash, hashToHex, draw, aStar, getFromRoute |
