<- CRPL reference <- Terrain and Wall Commands
| Arguments | Result | Notation |
|---|---|---|
| X1, Y1, X2, Y2, min_height, max_height, avoid_occupied, full_cells_only | a list. | X1 Y1 X2 Y2 i1 i2 b1 b2 – l1 |
Returns a list of packed coordinates in the y*MapWidth+x format that satisfy the following conditions:
Enjoy this script that draws a path between the mouse and the nearest anticreeper, avoiding terrain higher or lower than the source or destination, as well as buildings. This script requires a vertically aligned line like image in image slot Custom0.
#Clean up from last frame
Self RemoveImages
#move the core to the mouse.
GetMouseCell SetCurrentCoords
#create target coords
@testCoords ->y ->x
#create the path (from me to (x,y))
CurrentCoords <-x <-y
CurrentCoords GetTerrain <-x <-y GetTerrain @sort2
TRUE FALSE PathFindTerrain ->list
@drawTheLightning
:awake
TRUE OperateWhilePaused
#Replace this with whatever you want to path to.
:testCoords
CurrentCoords 999 FALSE FALSE FALSE TRUE GetNearestGroundEnemy
#This function sorts the two items on the stack from lowest to highest
:sort2
->b ->a
<-a <-b lt if <-a <-b else <-b <-a endif
:drawTheLightning
#initialize the old coordinates
CurrentCoords CellToPixel ->oldY ->oldX
#Memorize the core position, as images draw relative to the core.
CurrentCoords CellToPixel ->y0 ->x0
#for each square in the path
<-list GetListCount 0 do
#load the line graphic and paint it red
Self I "Custom0" SetImage
Self I 255 0 0 255 SetImageColor
#unpack the coordinates (a=y*w+x)
<-list I GetListElement dup ->a
<-a MapWidth mod <-a MapWidth div CellToPixel ->y ->x
#move the line between the last and current coordinates
Self I
<-x <-oldX add 2 div <-x0 sub
<-y <-oldY add 2 div <-y0 sub
0 SetImagePosition
#use arctan to get the slope of the line
Self I
<-x <-oldX sub
<-oldY <-y sub atan2
SetImageRotation
#stretch the line to the appropriate length
Self I .25
<-x <-oldX sub dup mul
<-y <-oldY sub dup mul add sqrt 22 div
SetImageScale
#store the old coordinates
<-x ->oldX
<-y ->oldY
loop