View difference between Paste ID: qVrxYAU7 and HmRMny7b
SHOW: | | - or go back to the newest paste.
1
Style = {
2
 CDeflt = colors.white,
3
 BGDeflt = colors.blue,
4
 CTitle = colors.black,
5
 BGTitle = colors.cyan,
6
 CWarn = colors.white,
7
 BGWarn = colors.red
8
}
9
10
function SetColorDeflt()
11
 term.setBackgroundColor(Style.BGDeflt)
12
 term.setTextColor(Style.CDeflt)
13
end
14
15
function SetColorTitle()
16
 term.setBackgroundColor(Style.BGTitle)
17
 term.setTextColor(Style.CTitle)
18
end
19
20
function SetColorWarn()
21
 term.setBackgroundColor(Style.BGWarn)
22
 term.setTextColor(Style.CWarn)
23
end
24
25
function Clear()
26
 term.clear()
27
 term.setCursorPos(1,1)
28
end
29
30
function Show(Text)
31
 term.write(Text)
32
 local xt,yt = term.getCursorPos()
33
 term.setCursorPos(1, yt+1)
34
end
35
36
function ShowTitle(Text)
37
 SetColorTitle()
38
 term.setCursorPos(12, 1)
39
 Show(Text)
40
 SetColorDeflt()
41
end
42
43
function ShowMenu(Text)
44
 term.write(Text)
45
 local xt, yt = term.getCursorPos()
46
 for i = xt, 51 do
47
  term.write(" ")
48
 end
49
 term.setCursorPos(1, yt+1)
50
end
51
52
function ShowWarning(Text)
53
  SetColorWarn()
54
  term.setCursorPos(10, 19)
55
  term.write(" "..Text.." ")
56
  SetColorDeflt()
57
end
58
59
function SaveData()
60
 local file = fs.open("shipdata.txt", "w")
61
 file.writeLine(textutils.serialize(SData))
62
 file.close()
63
end
64
65
function ReadData()
66
 local file = fs.open("shipdata.txt", "r")
67
 SData = textutils.unserialize(file.readAll())
68
 file.close()
69
end
70
71
function Explode(d, p)
72
 local t, ll
73
 t = {}
74
 ll = 0
75
 if(#p == 1) then return {p} end
76
 while true do
77
  l = string.find(p ,d, ll, true)
78
  if l ~= nil then 
79
   table.insert(t, string.sub(p, ll, l-1))
80
   ll = l+1
81
  else
82
   table.insert(t, string.sub(p, ll))
83
   break
84
  end
85
 end
86
 return t
87
end
88
89
function ShowDirection()
90
 if SData.Direction == 1 then
91
  Show(" Direction        = Up")
92
 elseif SData.Direction == 2 then
93
  Show(" Direction        = Down")
94
 elseif SData.Direction == 0 then
95
  Show(" Direction        = Front")
96
 elseif SData.Direction == 180 then
97
  Show(" Direction        = Back")
98
 elseif SData.Direction == 90 then
99
  Show(" Direction        = Left")
100
 elseif SData.Direction == 255 then
101
  Show(" Direction        = Right")
102
 end
103
end
104
105
function CalcRealDistance()
106
 if IsInHyper then
107
  RealDistance = SData.Distance * 100
108
  MinimumDistance = 1
109
  JumpCost = (1000 * Weight) + (1000 * SData.Distance)
110
 else
111
  if SData.Direction == 1 or SData.Direction == 2 then
112
   MinimumDistance = GUp + GDown
113
   RealDistance = SData.Distance + MinimumDistance
114
  elseif SData.Direction == 0 or SData.Direction == 180 then
115
   MinimumDistance = GFront + GBack
116
   RealDistance = SData.Distance + MinimumDistance
117
  elseif SData.Direction == 90 or SData.Direction == 255 then
118
   MinimumDistance = GLeft + GRight
119
   RealDistance = SData.Distance + MinimumDistance
120
  end
121
  MinimumDistance = MinimumDistance + 1
122
  JumpCost = (10 * Weight) + (100 * SData.Distance)
123
 end
124
end
125
126
function CalcNewCoords(cx, cy, cz)
127
 local res = {x=cx, y=cy, z=cz}
128
 if SData.Direction == 1 then
129
  res.y = res.y + RealDistance
130
 elseif SData.Direction == 2 then
131
  res.y = res.y - RealDistance
132
 end
133
 local dx = warp.get_dx()
134
 local dz = warp.get_dz()
135
 if dx ~= 0 then
136
  if SData.Direction == 0 then
137
   res.x = res.x + (RealDistance * dx)
138
  elseif SData.Direction == 180 then
139
   res.x = res.x - (RealDistance * dx)
140
  elseif SData.Direction == 90 then
141
   res.z = res.z + (RealDistance * dx)
142
  elseif SData.Direction == 255 then
143
   res.z = res.z - (RealDistance * dx)
144
  end
145
 else
146
  if SData.Direction == 0 then
147
   res.z = res.z + (RealDistance * dz)
148
  elseif SData.Direction == 180 then
149
   res.z = res.z - (RealDistance * dz)
150
  elseif SData.Direction == 90 then
151
   res.x = res.x + (RealDistance * dz)
152
  elseif SData.Direction == 255 then
153
   res.x = res.x - (RealDistance * dz)
154
  end
155
 end
156
 return res
157
end
158
159
function ShowInfo()
160
 ShowTitle(Title)
161
 Show("Core:")
162
 Show(" x, y, z          = "..X..", "..Y..", "..Z)
163
 local energy = warp.get_energy_level()
164
 Show(" Energy           = "..math.floor(energy / 1000000).." % ("..energy.."EU)")
165
 Show(" Attached players = "..warp.get_attached_players())
166
 Show("Dimensions:")
167
 Show(" Front, Right, Up = "..GFront..", "..GRight..", "..GUp)
168
 Show(" Back, Left, Down = "..GBack..", "..GLeft..", "..GDown)
169
 Show(" Size             = "..Weight.." blocks")
170
 Show("Warp data:")
171
 ShowDirection()
172
 local dest = CalcNewCoords(X, Y, Z)
173
 Show(" Distance         = "..RealDistance.." ("..JumpCost.."EU, "..math.floor(energy/JumpCost).." jumps)")
174
 Show(" Dest.coordinates = "..dest.x..", "..dest.y..", "..dest.z)
175
 if SData.Summon then
176
  Show(" Summon after     = Yes")
177
 else
178
  Show(" Summon after     = No")
179
 end
180
end
181
182
function Confirm()
183
 ShowWarning("Are you sure? (y/n)")
184
 local event, keycode = os.pullEvent("key")
185
 if keycode == 21 then
186
  return true
187
 else
188
  return false
189
 end
190
end
191
192
function Warp()
193
 rs.setOutput(Alarm, false)
194
 sleep(1)
195
 warp.set_direction(SData.Direction)
196
 if IsInHyper then
197
  warp.set_mode(2)
198
 else
199
  warp.set_mode(1)
200
 end
201
 warp.do_jump()
202
end
203
204
function SetDistance()
205
 Clear()
206
 ShowTitle("<====  Set distance  ====>")
207
 SData.Distance = 0
208
 CalcRealDistance()
209
 MaximumDistance = MinimumDistance + 127
210
 if IsInHyper then
211
  term.write("Distance * 100 (min "..MinimumDistance..", max "..MaximumDistance.."): ")
212
 else
213
  term.write("Distance (min "..MinimumDistance..", max "..MaximumDistance.."): ")
214
 end
215
 sleep(0.3)
216
 SData.Distance = tonumber(read())
217
 if SData.Distance == nil then SData.Distance = 1 end
218
 if SData.Distance < MinimumDistance or SData.Distance > MaximumDistance then
219
  SData.Distance = 1
220
  ShowWarning("Wrong distance. Try again.")
221
  os.pullEvent("key")
222
  CalcRealDistance()
223
 else
224
  if not IsInHyper then
225
   SData.Distance = SData.Distance - RealDistance
226
  end
227
  warp.set_distance(SData.Distance)
228
  CalcRealDistance()
229
 end
230
end
231
232
function SetDirection()
233
 local drun = true
234
 while(drun) do
235
  Clear()
236
  ShowTitle("<==== Set direction ====>")
237
  ShowDirection()
238
  term.setCursorPos(1, 16)
239
  SetColorTitle()
240
  ShowMenu("Use directional keys")
241
  ShowMenu("W/S keys for Up/Down")
242
  ShowMenu("Enter - confirm")
243
  SetColorDeflt()
244
  local event, keycode = os.pullEvent("key")
245
  if keycode == 200 then
246
   SData.Direction = 0
247
  elseif keycode == 17 then
248
   SData.Direction = 1
249
  elseif keycode == 203 then
250
   SData.Direction = 90
251
  elseif keycode == 205 then
252
   SData.Direction = 255
253
  elseif keycode == 208 then
254
   SData.Direction = 180
255
  elseif keycode == 31 then
256
   SData.Direction = 2
257
  elseif keycode == 28 then
258
   drun = false
259
  end
260
 end
261
end
262
263
function SetDimensions()
264
 Clear()
265
 sleep(0.3)
266
 ShowTitle("<==== Set dimensions ====>")
267
 term.write(" Front ("..GFront..") : ")
268
 GFront = tonumber(read())
269
 term.write(" Right ("..GRight..") : ")
270
 GRight = tonumber(read())
271
 term.write(" Up    ("..GUp..") : ")
272
 GUp = tonumber(read())
273
 term.write(" Back  ("..GBack..") : ")
274
 GBack = tonumber(read())
275
 term.write(" Left  ("..GLeft..") : ")
276
 GLeft = tonumber(read())
277
 term.write(" Down  ("..GDown..") : ")
278
 GDown = tonumber(read())
279
 term.write("Setting dimensions...")
280
 warp.dim_setp(GFront, GRight, GUp)
281
 warp.dim_setn(GBack, GLeft, GDown)
282
end
283
284
function Summon()
285
 Clear()
286
 ShowTitle("<==== Summon players ====>")
287
 local players = Explode(",", warp.get_attached_players())
288
 for i = 1, #players do
289
  Show(i..". "..players[i])
290
 end
291
 SetColorTitle()
292
 ShowMenu("Enter player number")
293
 ShowMenu("or press enter to summon everyone")
294
 SetColorDeflt()
295
 sleep(0.3)
296
 term.write(":")
297
 local input = read()
298
 if input == "" then
299
  warp.summon_all()
300
 else
301
  input = tonumber(input)
302
  warp.summon(input - 1)
303
 end
304
end
305
306
function JumpToBeacon()
307
 Clear()
308
 ShowTitle("<==== Jump to beacon ====>")
309
 sleep(0.3)
310
 term.write("Enter beacon frequency: ")
311
 local freq = tostring(read())
312
 rs.setOutput(Alarm, true)
313
 if Confirm() then
314
  rs.setOutput(Alarm, false)
315
  warp.set_mode(4)
316
  warp.set_beacon_frequency(freq)
317
  warp.do_jump()
318
 end
319
 rs.setOutput(Alarm, false)
320
end
321
322
function JumpToGate()
323
 Clear()
324
 ShowTitle("<==== Jump to JumpGate ====>")
325
 sleep(0.3)
326
 term.write("Enter jumpgate name: ")
327
 local name = tostring(read())
328
 rs.setOutput(Alarm, true)
329
 if Confirm() then
330
  rs.setOutput(Alarm, false)
331
  warp.set_mode(6)
332
  warp.set_target_jumpgate(name)
333
  warp.do_jump()
334
 end
335
 rs.setOutput(Alarm, false)
336
end
337
338-
function SetShipName()
338+
339
340-
 ShowTitle("<==== Set ship name ====>")
340+
341
else
342-
 term.write("Enter ship name: ")
342+
343-
 SData.Shipname = tostring(read())
343+
344-
 os.setComputerLabel(SData.Shipname)
344+
345
  Direction = 0,
346-
 os.reboot()
346+
347
 }
348
end
349
350
SetColorDeflt()
351
352
Side = { "bottom", "top", "back", "left", "right" }
353
for i = 1,5 do
354
 end
355
end
356
357
358
Title = "<awesome and giant imperial cruiser>"
359
360
if SData.Summon then
361
 warp.summon_all()
362
end
363
364-
 if peripheral.getType(Side[i]) == "warpcore" then
364+
365-
  warp = peripheral.wrap(Side[i])
365+
366-
  break
366+
367
repeat
368
 X = warp.get_x()
369
 sleep(0.3)
370-
if SData.Shipname == "" then
370+
371-
 SetShipName()
371+
372
Z = warp.get_z()
373
Weight = warp.get_ship_size()
374-
Title = "<Jump-S 1.6.1 \""..SData.Shipname.."\">"
374+
375
CalcRealDistance()
376
377
warp.set_mode(1)
378
379
mainloop = true
380
while(mainloop) do
381
 Clear()
382
 ShowInfo()
383
 term.setCursorPos(1, 15)
384
 SetColorTitle()
385
 ShowMenu("D - Dimensions, M - Toggle summon, ")
386
 ShowMenu("S - Set Warp Data, J - Jump, G - Jump to JumpGate")
387
 ShowMenu("B - Jump to Beacon, H -Jump to Hyperspace")
388
 ShowMenu("C - Summon, X - Shutdown WarpCore and Exit")
389
 SetColorDeflt()
390
 local event, keycode = os.pullEvent("key")
391
 if keycode == 31 then
392
  SetDirection()
393
  SetDistance()
394
  SaveData()
395
 elseif keycode == 50 then
396
  if SData.Summon then
397
   SData.Summon = false
398
  else
399
   SData.Summon = true
400
  end
401-
 ShowMenu("D - Dimensions, M - Toggle summon, N - Ship name")
401+
402
 elseif keycode == 32 then
403
  SetDimensions()
404
  SaveData()
405
 elseif keycode == 36 then
406
  rs.setOutput(Alarm, true)
407
  if Confirm() then
408
   Warp()
409
  end
410
  rs.setOutput(Alarm, false)
411
 elseif keycode == 46 then
412
  Summon()
413
 elseif keycode == 48 then
414
  JumpToBeacon()
415
 elseif keycode == 34 then
416
  JumpToGate()
417
 elseif keycode == 35 then
418
  rs.setOutput(Alarm, true)
419
  if Confirm() then
420
   rs.setOutput(Alarm, false)
421
   warp.set_mode(5)
422
   warp.do_jump()
423
  end
424
  rs.setOutput(Alarm, false) elseif keycode == 45 then
425
426
  mainloop = false
427
 elseif keycode == 49 then
428
  
429
 end
430
end
431
432
if SData.Summon then
433
 SData.Summon = false
434
 SaveData()
435
end
436
Clear()
437
print("wish you good")
438
warp.set_mode(0)
439
sleep(0.5)
440
os.shutdown()