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

ICBM Mod Methodical Help

Started by Andrew2060, 20 March 2017 - 10:08 PM
Andrew2060 #1
Posted 20 March 2017 - 11:08 PM
Hi.

I created a program that shoots down incoming missiles by tracking them via radar and then tasking wireless slave pc's.

Radar – > ABM Server –>Slave PC's –> Launchers attached to Slave PC's –>Launch Interceptor missiles in sequence.

I have tried to improve it with these three ideas:

1. Somehow predict incoming missile trajectories so that interceptor missiles fire at the projected point rather than at a previous one.
- This basically means that my interceptors should hit incoming missiles more precisely, rather than fire at previous altitudes.
- This way the interceptors don't fly past the missiles but get as close as possible to them by going to their projected point.
- I tried to use math to derive a formula based on a simple y=mx+B function and use the slope to find the next point.
- Didn't work out so well.

2. It would be nice if someone could write me some code in which slave PC's tell the master PC what their current missile is:
- Method for that: getMissile()
- Currently it only prints a list of available silos to the master and their ID.
- I was wondering if someone could tell me how i could let the master receive and print the loads of each slave.
- Also if it could tell the master if the slave is armed or not.

what i want it to do:

Silos List:

[1] Id: (id here) | Armed Status: (armed/disarmed) | Missile: (Missile Type)

my master code: http://pastebin.com/zTJ6WFj7
my slave: http://pastebin.com/tGN8JaPW

Thanks!
Edited on 20 March 2017 - 10:11 PM
Andrew2060 #2
Posted 21 March 2017 - 10:11 PM
I need some serious help and lecturing on rednet/tables.

It just seems as if though i cant send a table wirelessly.
Lupus590 #3
Posted 21 March 2017 - 10:18 PM
before you send your table pass it through this: http://computercraft.info/wiki/Textutils.serialize

when you receive, get the table back with this: http://computercraft.info/wiki/Textutils.unserialize
valithor #4
Posted 21 March 2017 - 11:10 PM
It depends on what version of the mod you are using and what you are trying to send in the table. In older versions of the mod you had to serialize the table yourself prior to sending it, in newer versions you could send tables directly.

In both newer versions and older versions you are unable to send functions, which you are trying to do on line 42 (getSiloState returns a table with the function os.getComputerID, idk what the peripheral returns).

What version of the mod are you using, and what do the tables that you are sending look like?
Andrew2060 #5
Posted 22 March 2017 - 09:08 AM
Im using the latest version for 1.7.10.

The table from the slave should look like this:

[Silo#] [ComputerID] [MissileType] [CurrentTarget] [Armed/Disarmed]
1 0 Nuclear 0, 0 , 0 Armed
2 1 Nuclear 0, 0 , 0 Disarmed.
3 2 etc
4 3 etc

Translated from the coded Table:

local siloData = {
["Msg"] = "ABM",
["Id"] = os.getComputerId(),
["Missile"] = missile,
["Target"] = target,
["Armed"] = armed
}

I want this to be sent wirelessly from the slave PC to the Master PC.
This way the MasterPC prints all the information in the table and can still use the multiple ID's to launch missiles.

Currently, the Master does a public ping via rednet.broadcast, and if any PC sends back the message "ABM" they get paired to the master.
I want this to remain, but at the same time i want it to receive additonal information about each silo.

So the master broadcasts "ABM1" and the slave sends back "ABM" (like ping/pong).

SpoilerMaster (receiver code):
  • rednet.broadcast("ABM1")
  • repeat
  • local id, msg = rednet.receive(waitDelay)
  • if msg == "ABM" then table.insert(silos, id) end
  • until not id
Slave (receiver code):
  • if (msg == "ABM1") then
  • print(" master=", id)
  • masterID = id;
  • rednet.send(masterID, "ABM")

my launch protocol:

maptab = peripheral.call("back","getEntities")
maptxt = textutils.serialize(maptab)
if maptxt ~= "{}" then
allDat = 0
for num in pairs(maptab) do
allDat = allDat+1
end
targets = allDat/3
for i=0,targets-1 do
		local msg = {["x"] = math.floor(maptab["x_"..i]), ["y"] = math.floor(maptab["y_"..i]), ["z"] = math.floor(maptab["z_"..i])}

		print("Incoming Missile Threat #" .. i .. " at X:" .. msg.x .. " Y:" .. msg.y .. " Z:" .. msg.z)
		print("Launching " .. countersPerMissile .. " of ABM Missile CounterMeasures...\n")

		for i = 1, countersPerMissile do
			rednet.send(silos[curSilo], msg)
			curSilo = (curSilo == #silos) and 1 or (curSilo + 1)
			sleep(missileDelay)
Edited on 22 March 2017 - 08:13 AM
Andrew2060 #6
Posted 22 March 2017 - 09:36 AM
snip
Edited on 22 March 2017 - 01:40 PM
Andrew2060 #7
Posted 22 March 2017 - 02:36 PM
Alright so i got the information to be sent wirelessly in near perfect form.

However there are a few problems i don't know how to fix.

1. The Screen prints the appropriate Silo #'s and their respective ID #'s, but only uses 1 slave's information to fill both's other fields.

For example rather than saying this:
Silo #1 Id#1 Type: Nuclear
Silo #2 Id#2 Type: Conventional

It says:



There are two different computers with two different missiles and two different targets.
It should print the information respective to each individual silo, rather than copy paste 1 silo's information into the fields of the others.

2. What the computer should return if no missile is present, or if it is an anti-ballistic missile it should abbreviate it to A.B.M.
I know this sounds easy for a lot of people to do as a general if/else combo, but i can't seem to know where to put either.
Basically the slave's will crash when they find out that there is no missile, i dont know how to make them return another value.


3. How do i make the Target key of the table print x,y,z values?, right now it only prints X.


New working codes:
Master: http://pastebin.com/zTJ6WFj7
Slave: http://pastebin.com/fZ5xeB99
Edited on 23 March 2017 - 08:31 AM
Bomb Bloke #8
Posted 23 March 2017 - 11:18 PM
It should print the information respective to each individual silo, rather than copy paste 1 silo's information into the fields of the others.

At the moment, you've got this loop:

  for k, v in ipairs(data) do
  print("[S#:".. k .."] [ID:" .. v .."] [Type:".. silos[2] .. "] [Target:".. silos[3] .. "]")
 end

"silos[2]" and "silos[3]" are going to hold the same values on every iteration, so you'll see the same text written out next to each k/v.

Your actual "silos" table is a little messy; you've got four indexes in there for every one silo. For example, the target of the first silo is defined at silos[3], the target of the second at silos[7], the third at silos[11], and so on. You could have your code calculate these positions:


  for k, v in ipairs(data) do
  print("[S#:".. k .."] [ID:" .. v .."] [Type:".. silos[(k-1) * 4 + 2] .. "] [Target:".. silos[(k-1) * 4 + 3] .. "]")
 end

… but it'd be neater to redo your silos table:

repeat
	local id, msg = rednet.receive(waitDelay)
	
	if type(msg) == "table" and msg.Msg == "ABM" then
		table.insert(silos, msg)
	end
until not id

… so that you can later print out the data like this:

for k, v in ipairs(silos) do
	print("[S#:".. k .."] [ID:" .. v.ID .."] [Type:".. v.Missile .. "] [Target:".. v.Target .. "]")
end

3. How do i make the Target key of the table print x,y,z values?, right now it only prints X.

Are you sure that's X, and not an angle or something? Do you have any documentation for missilesilo.getTarget()?
Andrew2060 #9
Posted 25 March 2017 - 09:45 AM
Thank you.
The missilesilo.getTarget() returns X, Y, Z Coordinates.
And i turn them into a single string… then put them into the table as "target" and send it.
However when printed on the master, the "target" returns only the X: Value.

I know that this is the X value because I checked the ICBM Launch Panel Block, and it matched.

I guess maybe it's trying to assign x, y and z in the table differently?
Bomb Bloke #10
Posted 26 March 2017 - 02:11 AM
The missilesilo.getTarget() returns X, Y, Z Coordinates.

Assuming it returns three separate values, that means you won't be able to pass them all to tostring() at the same time - that function only accepts one input at once, and ignores any others you hand it.

You could take the values into a new table:

local  target = {missilesilo.getTarget()}

Or manually assign them to more descriptive keys:

local siloData = {
	["Msg"] = "ABM",
	["ID"] = os.getComputerID(),
	["Missile"] = currentmissile
}

siloData.tX, siloData.tY, siloData.tZ = missilesilo.getTarget()