This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Barney's profile picture

Ship control

Started by Barney, 20 December 2012 - 11:03 PM
Barney #1
Posted 21 December 2012 - 12:03 AM
This is OS for control ship's warpdrives on industrial Aerospace server. Feel free to comment.

Computer need a monitor and bundled cable on it's sides (directions changeable in code)

Some pics:
Spoiler



Code:

Spoiler

args = {...}
  shell.run('pass')
		--C
  counter = {
   forward = {
	 Inc = colors.lime,
	 Dec = colors.yellow,
	 value = 0,
	 b = 0
   },
   back = {
	 Inc = colors.red,
	 Dec = colors.white,
	 value = 0,
	 b = 0
   },
   right = {
	 Inc = colors.gray,
	 Dec = colors.orange,
	 value = 0,
	 b = 0
   },
   left = {
	 Inc = colors.blue,
	 Dec = colors.brown,
	 value = 0,
	 b = 0
   },
   up = {
	 Inc = colors.purple,
	 Dec = colors.lightGray,
	 value = 0,
	 b = 0
   },
   down = {
	 Inc = colors.cyan,
	 Dec = colors.black,
	 value = 0,
	 b = 0
   },
   mult = {
	 Inc = colors.pink,
	 Dec = colors.lightBlue,
	 value = 0,
	 b = 0
   }
		}
  sides = {'forward','back','right','left','up','down','mult'}
--Var
	start = colors.green
	m = peripheral.wrap("left")
	interval = 0.2
	side = "bottom"
	RESET = counter.forward.Dec + counter.back.Dec + counter.right.Dec +
	counter.left.Dec + counter.up.Dec +  counter.down.Dec + counter.mult.Dec
--Functions
function setDir()
	write('Changing direction...')
	pmc('CHANGING DIRECTION...',m)
for n = 1, 7 do
  if counter[sides[n]].b > 0 then
   impulse(counter[sides[n]].b, counter[sides[n]].Inc)
   counter[sides[n]].value = counter[sides[n]].value + counter[sides[n]].b
  end
end
	Update()		  
	UpdateTerm()		  
clearBuffers()  
end
function Reset()
write("Resetting...")
pmc("RESETTING...",m)
	impulse(63, RESET)	  
	for n = 1, 7 do	  
  counter[sides[n]].value = 0  
end
	Update()	  
	print(" Done.")	  
	clearBuffers()
end	  
function impulse(n, clr)
	for j = 1,n do
		rs.setBundledOutput(side, clr)
		sleep(interval)	  
		rs.setBundledOutput(side, 0)	  
  sleep(interval)		  
	end
end
function changeDir(ch,chText)
	write(chText)
counter[ch].b = tonumber(read())
	setDir()
end
function head(count,str, monitor)
	local mon  = monitor
	mon.clear()
	mon.setCursorPos(1,count)
	x,y = mon.getSize()
	n = (x/2)
	str1 = '='
	for i = 1,n do
		mon.write(str1)
	end
	n2 = #str / 2
	mon.setCursorPos(n - n2 + 1,count)
	mon.write(str)
	for i= 1,x do
		mon.write(str1)
	end
end	  
function pmc( textCenter, monitor)
	local mon  = monitor
	mon.clear()
	local x, y = mon.getSize()	
	local centerYPos = y / 2	
	local centerXStartingPos = ( x - string.len(textCenter) ) / 2	
	mon.setCursorPos( centerXStartingPos, centerYPos )	
	mon.write( textCenter )	
end		  
function JMP()
	print("Jumping...")
	pmc("JUMPING...", m)
	rs.setBundledOutput(side, start)
	sleep(3*interval)
	rs.setBundledOutput(side, 0)
	Update()
end
function Update()
	head(1, " Jump direction ", m)
	m.setCursorPos(1,2)
	m.write('Up:		 ' .. counter.up.value)
	m.setCursorPos(1,3)
	m.write('Down:	   ' .. counter.down.value)
	m.setCursorPos(1,4)
	m.write('Right:	  ' .. counter.right.value)
	m.setCursorPos(1,5)
	m.write('Left:	   ' .. counter.left.value)
	m.setCursorPos(1,6)
	m.write('Forward:	' .. counter.forward.value)
	m.setCursorPos(1,7)
	m.write('Back:	   ' .. counter.back.value)
	m.setCursorPos(1,9)
	m.write('Multiplier: ' .. counter.mult.value)
end
function UpdateTerm()
	head(1, " ArchOS ", term)
term.setCursorPos(1,2)
print("Enter > Jump")
	print("D	 >  Change direction")
	print("E	 >  Change multiplier ")
	print('')
	print("F	 >  Full reset direction")
	print("R	 >  Buffer reset direction")
print("M	 >  Multiplier reset")
	print('')
print("W	 >  Decrement side")
	print("C	 >  Summon crew")
	print('')
	print("Q	 >  Quit")
end
function CH()	  
head(1,' Use keys to choose direction ', term)
	term.setCursorPos(1,3)		  
	print('UP	  > 1		Ship size:')		  
	print('DOWN	> 2		 l: 116')
	print('RIGHT   > 3		 w: 63')
	print('LEFT	> 4		 h: 26')
	print('FORWARD > 5')
	print('BACK	> 6')
	print('')
	print('Quit	> Q')
	local is2 = true
	while is2 do			
	event, key = os.pullEvent()
	if event == "char" and key == "1" then
		changeDir('up','Enter value: ')
		is2 = false
	end
						if event == "char" and key == "2" then
								changeDir('down','Enter value: ')
								is2 = false
						end
						if event == "char" and key == "3" then
								changeDir('right','Enter value: ')
								is2 = false
						end
						if event == "char" and key == "4" then
								changeDir('left','Enter value: ')
								is2 = false
						end
						if event == "char" and key == "5" then
								changeDir('forward','Enter value: ')
								is2 = false
						end
						if event == "char" and key == "6" then
								changeDir('back','Enter value: ')
								is2 = false
						end
						if event == "char" and key == 'q' then
								is2 = false
						end
				end
		end
function Get(a1,a2,a3,a4,a5,a6,a7)
	local n = 0
	if a1 >= n then n = a1 end
	if a2 >= n then n = a2 end
	if a3 >= n then n = a3 end
	if a4 >= n then n = a4 end
	if a5 >= n then n = a5 end
	if a6 >= n then n = a6 end
	if a7 >= n then n = a7 end
	return n
end
function BufferReset()
	print("Buffer Resetting...")
	n = Get(UP, DOWN, RIGHT, LEFT, BACK, FORWARD, MULT)
	impulse(n, RESET)
	print("Buffers reseted")
	for n = 1, 7 do
  counter[sides[n]].value = 0
end
	clearBuffers()
	Update()
end
function clearBuffers()
for n = 1, 7 do
  counter[sides[n]].b = 0
end
end
--Start
local is = true
while is do
				Update()
				UpdateTerm()
				event, key = os.pullEvent()
				if(event == 'key' and key == 28) then
					JMP()
				end
				if(event == 'key' and key == 16) then
					exit()
				end
				if(event == 'key' and key == 46) then
					print("Summoning crew...")
					impulse(MULT,mult.Dec)
					JMP()
					counter.mult = 0
					counter.mult.b = 0
				end
				if(event == 'key' and key == 32) then
						CH()		  
				end
				if(event == 'key' and key == 18) then
	 head(1,' Multiplier ',term)
	 changeDir('mult','Enter value:')
				end
				if(event == 'key' and key == 33) then
					Reset()
				end
				if(event == 'key' and key == 19) then
					BufferReset()
				end
				if(event == 'key' and key == 22) then
					Update()
				end
	if(event == 'key' and key == 57) then
	 shell.run('pass')
	end
	if(event == 'key' and key == 50) then
	 print('Multiplier reset...')
	 impulse(26, counter.mult.Dec)
	 MULT = 0
	 counter.mult.b = 0
	end
if(event == 'key' and key == 17) then
  write('Enter side: ')
  s = read()
  write('Enter count: ')
  c = read()
  print('Decrementing...')
  impulse(c,counter[s]['Dec'])
  counter[s].value = counter[s].value - c
end
end

Thanks for watching.
Sammich Lord #2
Posted 21 December 2012 - 12:06 AM
This is something that we don't see every day.
tghnn #3
Posted 21 December 2012 - 12:49 AM
I see what you did there
^_^/>
Xfel #4
Posted 21 December 2012 - 03:27 AM
What mod did you use to create this?
Barney #5
Posted 21 December 2012 - 04:36 AM
What mod did you use to create this?

This is server-side mod which add warp engines for move constructions on long distances.
Leo Verto #6
Posted 21 December 2012 - 04:45 AM
What mod did you use to create this?
This is server-side mod which add warp engines for move constructions on long distances.
Is it publicly available?
Barney #7
Posted 21 December 2012 - 04:49 AM
Is it publicly available?
Mod isn't, but you can visit server. Also pages about engines exist in our wiki, but only at russian language now. You can use translator.

http://ru.aerospace.wikia.com/wiki/%D0%9F%D1%80%D1%8B%D0%B6%D0%BA%D0%BE%D0%B2%D1%8B%D0%B9_%D0%B2%D0%B0%D1%80%D0%BF%D0%B4%D1%80%D0%B0%D0%B9%D0%B2
Barney #8
Posted 22 December 2012 - 04:00 AM
Will upload new version of program in few days. Also, we're translating wiki pages so you can go to server and try jump engines with that program.

http://aerospace.wikia.com/wiki/Aerospace_Wiki