Guest User

IODN code - ver. 2

a guest
Sep 14th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.89 KB | None | 0 0
  1. local iod = elements.allocate("chem", "iod")
  2.  elements.element(iod, elements.element(elements.DEFAULT_PT_STNE))
  3.  elements.property(iod, "Name", "IODN")
  4.  elements.property(iod, "Colour", 0x1E1A2E)
  5.  elements.property(iod, "Description", "Iodine. Reactive non-metal. Sublimes.")
  6.  elements.property(iod, "Gravity", 1)
  7.  elements.property(iod, "Weight", 90)
  8.  elements.property(iod, "HeatConduct", 90)
  9.  elements.property(iod, "Hardness", 1)
  10.  
  11. local gasiod = elements.allocate("chem", "giod")
  12.  elements.element(gasiod, elements.element(elements.DEFAULT_PT_HYGN))
  13.  elements.property(gasiod, "Name", "GIOD")
  14.  elements.property(gasiod, "MenuVisible", 0)
  15.  elements.property(gasiod, "Gravity", 0.1)
  16.  elements.property(gasiod, "Diffusion", 1)
  17.  elements.property(gasiod, "Colour", 0x963296)
  18.  elements.property(gasiod, "Hardness", 1)
  19.  
  20. function propiod(i,x,y,s,nt)
  21.     local eltemp = tpt.get_property("temp", i)
  22.     local eltmp = tpt.get_property("tmp", i)
  23.      if eltemp >= 267.9 then
  24.         if eltemp < 386.85 then
  25.             local chance =  math.floor(150000 / ((eltemp - 265.9)*0.1)^3) -- solid phase equilibrium
  26.             if math.random(1, chance) == 1 then
  27.                 tpt.set_property("type", "giod", i)
  28.             end
  29.         end
  30.     end
  31.      if nt > 0 then
  32.         for dx = -1, 1, 1 do
  33.             for dy = -1, 1, 1 do
  34.                 local eltype = tpt.get_property("type", x+dx, y+dy)
  35.                 if (eltype == elements.DEFAULT_PT_BRMT or eltype == elements.DEFAULT_PT_IRON) then -- react with brmt or iron
  36.                     tpt.set_property("temp", eltemp + 3, i)
  37.                     if eltemp > 313.15 then
  38.                         tpt.set_property("temp", eltemp + 6, i)
  39.                     end
  40.                 end
  41.                  if eltype == elements.DEFAULT_PT_NEUT then -- change tmp to 1 and absorb neut
  42.                     if eltmp < 1 then
  43.                         tpt.set_property("tmp", 1, i)
  44.                         tpt.delete(x+dx, y+dy)
  45.                     end
  46.                 end
  47.             end
  48.         end
  49.     end
  50.      if eltmp == 1 then -- radioactive decay (tmp is 1)
  51.         if math.random(1, 500) == 1 then
  52.             local vxrand = math.random(-30,30)
  53.             local vyrand = math.random(-30,0)
  54.             if math.abs(vxrand) + math.abs(vyrand) > 15 then
  55.                 tpt.set_property("type", "elec", i)
  56.                 tpt.set_property("vx", vxrand/10, i)
  57.                 tpt.set_property("vy", vyrand/10, i)
  58.                 tpt.set_property("life", 680, i)
  59.                 tpt.create(x+math.random(-1,1), y+math.random(-1,1), "nble")
  60.             end
  61.         end
  62.     end
  63. end
  64.  
  65.  
  66. function propgasiod(i,x,y,s,nt)
  67.     local eltemp = tpt.get_property("temp", i)
  68.     local eltmp = tpt.get_property("temp", i)
  69.      if eltemp < 386.85 then
  70.         if eltemp >= 268.9 then
  71.             local chance = math.floor(((eltemp - 265.9)*0.1)^3 * 80) -- vapor phase equilibrium
  72.             if math.random(1, chance) == 1 then
  73.                 tpt.set_property("type", "iodn", i)
  74.             end
  75.         else
  76.             tpt.set_property("type", "iodn", i)
  77.         end
  78.     end
  79.      if nt > 0 then
  80.         for dx= -1, 1, 1 do
  81.             for dy = -1, 1, 1 do
  82.                 local eltype = tpt.get_property("type", x+dx, y+dy)
  83.                 if eltype == elements.DEFAULT_PT_BRMT then
  84.                     if eltemp > 356.85 then
  85.                         tpt.set_property("temp", eltemp + 96, i)
  86.                         if eltemp > 1203.15 then
  87.                             tpt.delete(x+dx, y+dy)
  88.                             tpt.create(x+dx, y+dy, "fire")
  89.                             tpt.set_property("type", "lava", i)
  90.                             tpt.set_property("ctype", "salt", i)
  91.                             return
  92.                         end
  93.                     end
  94.                 end
  95.                  if eltype == elements.DEFAULT_PT_IRON then
  96.                     tpt.set_property ("temp", eltemp + 2, i)
  97.                     if eltemp > 573.15 then
  98.                         tpt.set_property ("temp", eltemp + 5, i)
  99.                         if eltemp > 773.15 then
  100.                             tpt.set_property("temp", eltemp + 12, i)
  101.                             if eltemp > 1223.15 then
  102.                                 if math.random(1, 100) == 1 then
  103.                                     tpt.delete(x+dx, y+dy)
  104.                                     tpt.create(x+dx, y+dy, "fire")
  105.                                     tpt.set_property("type", "fire", x+dx, y+dy)
  106.                                     tpt.set_property("type", "lava", i)
  107.                                     tpt.set_property("ctype", "salt", i)
  108.                                     return
  109.                                 end
  110.                             end
  111.                         end
  112.                     end
  113.                 end
  114.                  if eltype == elements.DEFAULT_PT_NEUT then
  115.                     if tpt.get_property("tmp", i) < 1 then
  116.                         tpt.set_property("tmp", 1, i)
  117.                         tpt.delete(x+dx, y+dy)
  118.                     end
  119.                 end
  120.             end
  121.         end
  122.     end
  123.     if tpt.get_property("tmp", i) == 1 then
  124.         if math.random(1, 500) == 1 then
  125.             local vxrand = math.random(-30,30)
  126.             local vyrand = math.random(-30,30)
  127.             if math.abs(vxrand) + math.abs(vyrand) > 20 then
  128.                 tpt.set_property("type", "elec", i)
  129.                 tpt.set_property("vx", vxrand/10, i)
  130.                 tpt.set_property("vy", vyrand/10, i)
  131.                 tpt.set_property("life", 680, i)
  132.                 tpt.create(x+math.random(-1,1), y+math.random(-1,1), "nble")
  133.             end
  134.         end
  135.     end
  136. end
  137.  
  138.  
  139. function graphiod(i, colr, colg, colb)
  140.     if tpt.get_property("tmp2", i) == 0 then
  141.         tpt.set_property("tmp2", math.random(1,5) * 5, i)
  142.     end
  143.     local colfact = tpt.get_property("tmp2", i)
  144.     return 1, 0x00000001, 255, 24+colfact, 20+colfact, 40+colfact, 0, 0, 0, 0
  145. end
  146.  
  147. elements.property(iod, "HighTemperature", 386.85)
  148. elements.property(iod, "HighTemperatureTransition", elements.CHEM_PT_GIOD)
  149. elements.property(iod, "Update", propiod)
  150. elements.property(iod, "Graphics", graphiod)
  151. elements.property(gasiod, "Update", propgasiod)
Advertisement
Add Comment
Please, Sign In to add comment