Coder Social home page Coder Social logo

oc_icbm_addon's Introduction

ICBM OpenComputers

ICBM-Classic API integration for OpenComputers

Components

You can access the component by placing an adapter next to one of the following blocks:

  • Missile Launcher
  • Radar Station
  • Cruise Launcher
  • EMP Station

See the code snippets below for what functionality you can use.

Accesing the components

By address

local component = require("component")
local proxy = component.proxy("xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")

By searching through the components on component_name

local component = require("component")
local proxy = nil

-- Possible values: 
-- "component_missile_launcher", 
-- "component_emp_tower",
-- "component_radar_station", 
-- "component_cruise_launcher"
local component_name = "component_missile_launcher" 

for k,v in component.list() do
  local p = component.proxy(k)
  if not (p.isICBM == nil) and p.isICBM(component_name) then
    proxy = p
  end
end

Know issues

  • Missile launcher adapter changes address after save reload.

Code Snippets

Missile Launcher
local serialization = require("serialization")
local component = require("component")
local adress = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -- Put adress of the launcher here
 
-- Get the Launcher Component
local proxy = component.proxy(adress)
proxy.setTargetPos(math.random(100) + 320, math.random() + 350)
proxy.setDetonationHeight(math.random(150))
proxy.setFrequency(math.random(100))
proxy.setLockHeight(math.random(100))
 
print("Target location set to:")
print(serialization.serialize(proxy.getTargetPos()))
 
print("Target height set to:")
--print(proxy.getDetonationHeight())
 
print("Lock height is set to:")
print(proxy.getLockHeight())
 
print("Missile inaccuaracy is:")
print(proxy.getInaccuary())
 
print("Missile frequency is set to")
print(proxy.getFrequency())
 
if proxy.containsMissile() then
  print("Missile found, launching missile!")
  print(proxy.launchMissile()) -- Wil return true if sucess false otherwise
else
  print("Missile silo empty!")
end
Radar Station
local serialization = require("serialization")
local component = require("component")
local adress = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -- Put adress of the radar station here

-- Get the proxy
local proxy = component.proxy(adress)
proxy.setAlarmRange(math.random(100)+400)
proxy.setSafetyRange(math.random(100)+300)
proxy.setFrequency(math.random(100))
 
print("The alarm range is")
print(proxy.getAlarmRange())
 
print("The safety range is")
print(proxy.getSafetyRange())
 
print("The frequency is")
print(proxy.getFrequency())
 
print("Incoming missiles")
print(serialization.serialize(proxy.getIncomingMissiles())) 
-- {
--  {uuid:"xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", x: 10 y: 100, z : 10},
--  {uuid:"xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", x: 20 y: 140, z : 20}
-- }
EMP Tower
local serialization = require("serialization")
local component = require("component")
local adress = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -- Put adress of the EMP Tower here
 
-- Get the proxy
local proxy = component.proxy(adress)
proxy.setRadius(math.random(200)+300)
proxy.setMode(math.random(4)-1)
 
print("The current mode is:")
print(proxy.getMode())
 
print("The current radius is:")
print(proxy.getRadius())
 
print("Activating the emp:")
if proxy.isReady() then
    print(proxy.launch())
end
Cruise Launcher
local serialization = require("serialization")
local component = require("component")
local adress = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -- Put adress of the cruise launcher here
       
-- Get the proxy
local proxy = component.proxy(adress)
proxy.setTargetPos(math.random(100) + 320, math.random(20) + 70, math.random(100) + 400)
proxy.setFrequency(math.random(100))
 
print("Target location set to:")
print(serialization.serialize(proxy.getTargetPos()))
 
print("The frequency is")
print(proxy.getFrequency())
 
os.sleep(3)
 
if proxy.canLaunch() then
  print("Can launch mssile!")
  print(proxy.launch())
else
  print("Missile cannot be lanched")
end

Simple defense system

This is a simple system that will send an event when a missile has been detected and then will launch an anti-ballistic missile. With this setup the anti ballistic missile will hit about 25% of the targets depending on location where it is fired from.

radar.lua
local serialization = require("serialization")
local component = require("component")
local comp = require("computer")
local thread = require("thread")
local table = require("table")
 
local adress = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -- Put adress of the radar station here
 
-- Get the Launcher Component
local radar = component.proxy(adress)
local detected_missiles = {}
 
local function contains(uuid, list)
  for index, value in ipairs(list) do
    if value.UUID == uuid then
      return true
    end
  end
  return false
end
 
local function loop()
  local missiles = radar.getMissiles()
  local new_missiles = {}
   
  for index, value in ipairs(missiles) do
    if detected_missiles[value.UUID] == nil then
      detected_missiles[value.UUID] = value
      table.insert(new_missiles, value)
      comp.pushSignal("missile_detected", value)
    end
  end
   
  for key, detected_missile in pairs(detected_missiles) do
    if not contains(key, missiles) then
      detected_missiles[key] = nil
      comp.pushSignal("missile_lost", key)
    end
  end
   
end
 
local t = thread.create(function(a, b)
  while true do
    loop()
    os.sleep()
  end
end)
t:detach()
anti_missile_launcher.lua
local serialization = require("serialization")
local component = require("component")
local event = require("event")

local adress = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -- Put adress of the missile launcher here
 
-- Get the proxy
local proxy = component.proxy(adresses.missile_launcher)
 
print("Waiting for incoming missiles")
while true do
  local _, missile = event.pull("missile_detected")
  print("Found missile: " .. serialization.serialize(missile))
  proxy.setDetonationHeight(missile.y)
  proxy.launch(missile.x, missile.z)
  event.pull("missile_lost")
  os.sleep()
end

oc_icbm_addon's People

Contributors

arjanseijs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.