--elements
--alpha radiation
local alpha = elem.allocate("ORESPAWNTPT", "ALPH")
elem.element(elem.alpha, elem.element(elem.DEFAULT_PT_PHOT))
elem.property(elem.alpha, "Name", "ALPH")
elem.property(elem.alpha, "Description", "Weak radiation. Everything is blocking it.")
elem.property(elem.alpha, "Colour", 0xFF8C7BC4)
elem.property(elem.alpha, "MenuVisible", 1)
elem.property(elem.alpha, "MenuSection", elem.SC_NUCLEAR)
--berillium
local ber = elem.allocate("ORESPAWNTPT", "BELM")
elem.element(elem.ber, elem.element(elem.DEFAULT_PT_BMTL))
elem.property(elem.ber, "Name", "BELM")
elem.property(elem.ber, "Description", "Berillium. Turns alpha radiation into neutrons")
elem.property(elem.ber, "Colour", 0xFFCEE4EF)
elem.property(elem.ber, "MenuVisible", 1)
elem.property(elem.ber, "MenuSection", elem.SC_NUCLEAR)
--americium
local amer = elem.allocate("ORESPAWNTPT", "AMRC")
elem.element(elem.amer, elem.element(elem.DEFAULT_PT_PLUT))
elem.property(elem.amer, "Name", "AMRC")
elem.property(elem.amer, "Description", "Americium. Emits alpha radiation")
elem.property(elem.amer, "Colour", 0xFF90A8A9)
elem.property(elem.amer, "MenuVisible", 1)
elem.property(elem.amer, "MenuSection", elem.SC_NUCLEAR)
--thorium
local t = elem.allocate("ORESPAWNTPT", "THOR")
elem.element(elem.t, elem.element(elem.DEFAULT_PT_PLUT))
elem.property(elem.t, "Name", "THOR")
elem.property(elem.t, "Description", "Thorium. Heated by neutrons")
elem.property(elem.t, "Colour", 0xFF425141)
elem.property(elem.t, "MenuVisible", 1)
elem.property(elem.t, "MenuSection", elem.SC_NUCLEAR)
--peltier element
local p = elem.allocate("ORESPAWNTPT", "PELT")
elem.element(elem.p, elem.element(elem.DEFAULT_PT_CRMC))
elem.property(elem.p, "Name", "PELT")
elem.property(elem.p, "Description", "Peltier element. Creates electricity from temperature differences")
elem.property(elem.p, "Colour", 0xFFEED0DC)
elem.property(elem.p, "MenuVisible", 1)
elem.property(elem.p, "MenuSection", elem.SC_NUCLEAR)
elem.property(elem., "Properties", elem.TYPE_SOLID + elem.PROP_CONDUCTS + elem.PROP_HOT_GLOW)
--reactions
--alpha radiation
elem.property(elem.amer, "Update", function(i, x, y, s, n)
if s ~= n then
r = sim.partID(x + math.random(-1, 1), y + math.random(-1, 1))
if r == nil then
sim.createPart(1, ry, rx, elements.alpha)
end
end
end)
--ber
elem.property(elem.ber, "Update", function(index, x, y, surround_space, nt)
local neighbors = sim.neighbors(x, y, 1, 1)
for n in neighbors do
if sim.partProperty(n, "type") == elem.alpha then
sim.partChangeType(n, elem.DEFAULT_PT_NEUT)
end
end
end
return
end)
--thorium heating
elem.property(elem.t, "Update", function(i, x, y, s, n)
if s ~= n then
r = sim.partID(x + math.random(-1, 1), y + math.random(-1, 1))
if r ~= nil then
local rt = sim.partProperty(r, "type")
if rt == elem.DEFAULT_PT_NEUT then
local heat = sim.partProperty(i, sim.TEMPERATURE)
sim.partProperty(i, "TEMPERATURE", heat+5)
sim.partKill(r)
end
end
end
end)
--peltie sparking
elem.property(elem.p, "Update", function(i, x, y, s, n)
if s ~= n then
local r = sim.partID(x + math.random(-1, 1), y + math.random(-1, 1))
if r ~= nil then
if sim.partProperty(i, sim.TEMPERATURE) > sim.partProperty(r, sim.TEMPERATURE) then
local heat = sim.partProperty(i, sim.TEMPERATURE) - sim.partProperty(r, sim.TEMPERATURE)
elseif sim.partProperty(i, sim.TEMPERATURE) < sim.partProperty(r, sim.TEMPERATURE) then
local heat = sim.partProperty(r, sim.TEMPERATURE) - sim.partProperty(i, sim.TEMPERATURE)
end
sim.partProperty(i, "ctype", p)
sim.partProperty(i, "life", 4)
sim.partProperty(i, "type", sprk)
sim.partKill(r)
end
end
end)
--see history for another script
The random particle probe could miss a neigboring particle for a long time (it has a 8:9 probability of missing a single particle) and selects the center particle itself sometimes (1:9 probability).
I personally would do this with sim.neighbors() or sim.partNeighbors() if you only want IDs. The advantages would be that the center is ignored, that you're guaranteed to find a neigboring particle every time there is one, and that you can filter the neigboring particle type on the fly.
local water_neighbors = sim.partNeighbors(x, y, 1, elements.DEFAULT_PT_WATR) if water_neighbors ~= nil then local neighbor_drop = water_neighbors[math.random(#water_neighbors)] ...
IOW you create a list of neighboring water particle IDs and if the list isn't empty you pick a random ID from the list.
(And don't use the old tpt.* interface.)