Stormworks: Build and Rescue

Stormworks: Build and Rescue

Navigation Map with Autopilot
SeaWeed  [开发者] 2024 年 8 月 18 日 上午 5:21
1st LUA Script (Unminified Code)
I=input
IGB=I.getBool
IGN=I.getNumber
O=output
OSB=O.setBool
OSN=O.setNumber
M=math
SM=map.screenToMap
MS=map.mapToScreen
S=screen
SC=S.setColor
DL=S.drawLine
DC=S.drawCircle
DCF=S.drawCircleF
DR=S.drawRect
DRF=S.drawRectF
DTX=S.drawText
DTXB=S.drawTextBox
T=table

R = property.getNumber('Colour Scheme (Red Value)')
G = property.getNumber('Colour Scheme (Green Value)')
B = property.getNumber('Colour Scheme (Blue Value)')

cntr = true
page = 1
mapX = 0
mapY = 0
num = 1

wpWX = {}
wpWY = {}

clearDist = property.getNumber('Minimum Distance to Clear Waypoints (m)')

function inRect(x,y,rectX,rectY,rectW,rectH)
return x >= rectX and y >= rectY and x < rectX+rectW and y < rectY+rectH
end

function onTick()
if page < 2 then
touch = IGB(1)
else
touch = false
end
cntrS = IGB(3)
wp = IGB(4)
hideUI = IGB(5)
delete = IGB(6)
clear = IGB(7)
settings = IGB(8)
exit = IGB(9)
lightT = IGB(10)
gridT = IGB(11)
keypad = IGB(12)
hideKeypad = IGB(13)
addWP = IGB(15)
jump = IGB(16)
APactive = IGB(19)

if cntrS then
cntr = true
end
if wp then
T.insert(wpWX,mapX)
T.insert(wpWY,mapY)
end
if hideUI then
page = 0
end
if delete then
T.remove(wpWX)
T.remove(wpWY)
end
if clear then
for i=1, #wpWX do
T.remove(wpWX)
T.remove(wpWY)
end
end
if settings then
page = 3
end
if keypad then
page = 2
end
if exit or hideKeypad then
page = 1
end
if addWP then
T.insert(wpWX,a)
T.insert(wpWY,b)
end
if jump then
page = 1
cntr = false
mapXs = a
mapYs = b
end

w = IGN(1)
h = IGN(2)
touchPX = IGN(3)
touchPY = IGN(4)
gpsWX = IGN(5)
gpsWY = IGN(6)
hdg = -IGN(7)
zoom = IGN(9)
UIL = IGN(10)
UIR = IGN(11)
a = IGN(15)
b = IGN(16)

if w < 96 then
smolX = 1
smolY = 7
else
smolX = h-12
smolY = h-6
end

if cntr then
mapXs = gpsWX
mapYs = gpsWY
end
mapX = mapX+(mapXs-mapX)*0.1
mapY = mapY+(mapYs-mapY)*0.1

gpsPX, gpsPY = MS(mapX,mapY,zoom,w,h,gpsWX,gpsWY)

hdgX1 = gpsPX+8*M.cos((hdg*2*M.pi)-0.5*M.pi)
hdgY1 = gpsPY+8*M.sin((hdg*2*M.pi)-0.5*M.pi)
hdgX2 = gpsPX+5*M.cos((hdg*2*M.pi)-0.7*M.pi)
hdgY2 = gpsPY+5*M.sin((hdg*2*M.pi)-0.7*M.pi)
hdgX3 = gpsPX+5*M.cos((hdg*2*M.pi)-0.3*M.pi)
hdgY3 = gpsPY+5*M.sin((hdg*2*M.pi)-0.3*M.pi)

if #wpWX > 0 then
dist = (((gpsWX-wpWX[1])^2)+((gpsWY-wpWY[1])^2))^0.5
WPbearingR = M.atan(wpWX[1]-gpsWX,wpWY[1]-gpsWY)/(M.pi*2)
if dist < clearDist then
if APactive and #wpWX == 1 then
lastWPclr = true
end
T.remove(wpWX,1)
T.remove(wpWY,1)
wpClr = true
end
end

if page == 1 then
if touch and touchPX > 8 and touchPX < w-7 then
touchC = true
else
if touchC then
cntr = false
mapXs, mapYs = SM(mapX,mapY,zoom,w,h,touchPX,touchPY)
end
touchC = false
end
elseif page == 0 then
if touch then
sC = true
else
if sC then
page = 1
end
sC = false
end
end

if lightT then
r1=0
g1=30
b1=35
r2=24
g2=68
b2=72
r3=90
g3=90
b3=90
r4=54
g4=72
b4=32
r5=100
g5=93
b5=41
r6=200
g6=200
b6=200
r7=15
g7=12
b7=12
r8=30
g8=24
b8=24
else
r1=0
g1=2
b1=4
r2=0
g2=3
b2=6
r3=10
g3=14
b3=20
r4=0
g4=12
b4=8
r5=10
g5=12
b5=15
r6=20
g6=20
b6=20
r7=2
g7=3
b7=5
r8=5
g8=7
b8=10
end

OSB(1,cntr)
OSB(2,wpClr)
OSB(3,lastWPclr)
wpClr = false
lastWPclr = false

OSN(1,page)
OSN(2,#wpWX)
OSN(3,dist)
OSN(4,WPbearingR)
end


function onDraw()
S.setMapColorOcean(r1,g1,b1)
S.setMapColorShallows(r2,g2,b2)
S.setMapColorLand(r3,g3,b3)
S.setMapColorGrass(r4,g4,b4)
S.setMapColorSand(r5,g5,b5)
S.setMapColorSnow(r6,g6,b6)
S.setMapColorRock(r7,g7,b7)
S.setMapColorGravel(r8,g8,b8)
S.drawMap(mapX,mapY,zoom)

oX,oY = MS(0,0,zoom,w,h,0,0)
eX,oY = MS(0,0,zoom,w,h,1,0)
e = eX-oX
if e*10000 < 38 then
grid = 10000
r = e*10000
rT = "10km"
elseif e*5000 < 38 then
grid = 5000
r = e*5000
rT = "5km"
elseif e*1000 < 38 then
grid = 1000
r = e*1000
rT = "1km"
elseif e*500 < 38 then
grid = 500
r = e*500
rT = "500m"
elseif e*100 < 38 then
grid = 100
r = e*100
rT = "100m"
elseif e*50 < 38 then
grid = 50
r = e*50
rT = "50m"
elseif e*10 < 38 then
grid = 10
r = e*10
rT = "10m"
end
gridX1,gridY1 = SM(mapX,mapY,zoom,w,h,0,h)
gridX2,gridY2 = SM(mapX,mapY,zoom,w,h,w,0)
gridX1 = M.floor(gridX1/grid)*grid
gridY1 = M.floor(gridY1/grid)*grid

if gridT then
if lightT then
SC(0,0,0,20)
else
SC(50,50,50,20)
end
for xx=gridX1,gridX2,grid do
x,y = MS(mapX,mapY,zoom,w,h,xx,y1)
DL(x,0,x,h)
end
for yy=gridY1,gridY2,grid do
x,y = MS(mapX,mapY,zoom,w,h,x1,yy)
DL(0,y,w,y)
end
end

if #wpWX > 0 then
wpPX, wpPY = MS(mapX,mapY,zoom,w,h,wpWX[1],wpWY[1])
SC(R*0.15,G*0.15,B*0.15)
DL(gpsPX,gpsPY,wpPX,wpPY)

for i=1, #wpWX do
wpPX, wpPY = MS(mapX,mapY,zoom,w,h,wpWX,wpWY)
if i > 1 then
SC(R*0.15,G*0.15,B*0.15)
DL(wpPX,wpPY,wpPX2,wpPY2)
end
SC(R*0.5,G*0.5,B*0.5)
DC(M.floor(wpPX),M.floor(wpPY),2)

wpPX2 = wpPX
wpPY2 = wpPY
end
end

SC(R,G,B)
DL(gpsPX,gpsPY,hdgX1,hdgY1)
DL(hdgX1,hdgY1,hdgX2,hdgY2)
DL(hdgX1,hdgY1,hdgX3,hdgY3)
DCF(gpsPX,gpsPY,2.5)

if touchC then
SC(R*0.5,G*0.5,B*0.5)
DCF(touchPX,touchPY,1.25)
end

if lightT then
SC(0,0,0)
else
SC(200,200,200)
end
DTXB(w-29+UIR,h-10,21,5,rT,1,0)
DR(w-9+UIR,h-4,0,2)
DR(w-9-r+UIR,h-4,0,2)
DR(w-9-r+UIR,h-2,r,0)

DTX(10+UIL,smolX,"X")
DTX(14+UIL,smolX,":")
DTX(10+UIL,smolY,"Y")
DTX(14+UIL,smolY,":")
DTX(17+UIL,smolX,string.format("%.0f", mapX))
DTX(17+UIL,smolY,string.format("%.0f", mapY))

if page == 1 and not cntr then
SC(R*0.15,G*0.15,B*0.15)
DR(w/2-6,h/2,4,0)
DR(w/2+2,h/2,4,0)
DR(w/2,h/2-6,0,4)
DR(w/2,h/2+2,0,4)
end
end
最后由 SeaWeed 编辑于; 2024 年 8 月 22 日 上午 11:30