-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeleporter.sprak
95 lines (84 loc) · 1.84 KB
/
Teleporter.sprak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#string msg = SetWorldPosition("Hotel_Exterior", 41, 35)
#SetWorldPosition('Ministry_ChamberOfNumbers',11,-110)
void main()
string first =Position()
string next =first
loop
next= Position()
if first != next
break
end
end
array firstPos=ToPos(first)
array nextPos=ToPos(next)
number dx = nextPos[0]-firstPos[0]
number dy = nextPos[1]-firstPos[1]
number tx=0
number ty=0
if dx != 0
if dx>0
tx=1
else
tx=-1
end
end
if dy != 0
if dy>0
ty=1
else
ty=-1
end
end
Print('init Warp-Drive')
Teleport(nextPos[0]+(tx*10),nextPos[1]+(ty*10))
Print('Fizzle')
# Teleport(42,37)
end
array ToPos(string p )
array pts = Split(p,',')
array x =Split(pts[0],': ')
array y =Split(pts[1],': ')
number rx = x[1]
number ry = y[1]
return [rx,ry]
end
bool HasSubstringAt(string haystack, number haystackPos, string needle)
number size = Count(haystack)
number remainingSize = size - haystackPos
number needleSize = Count(needle)
if (remainingSize < needleSize)
return False
end
loop i from 0 to (needleSize - 1)
if (haystack[haystackPos + i] != needle[i])
return False
end
end
return True
end
array Split(string str, string delimiter)
number size = Count(str)
number delimiterSize = Count(delimiter)
if (size <= 0)
return []
end
array ret = []
string currentLine = ""
number i = 0
loop
if (HasSubstringAt(str, i, delimiter))
Append(ret, currentLine)
currentLine = ""
i += delimiterSize
else
currentLine += str[i]
i += 1
end
if (i >= size)
break
end
end
Append(ret, currentLine)
return ret
end
main()