Advertisement
TPT_PL

The Space Toy (beta v0.6, man)

Aug 17th, 2016
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 74.50 KB | None | 0 0
  1. --[[
  2. THE SPACE TOY!!!
  3. Based on: Spacewars 1.0.0! Simlulate space in space.
  4. Script Version: beta v0.6
  5. ####################
  6. CHANGES:
  7. -- Added fighter lvl 2, with void ray (sadly same as laser) and stealth tech
  8. -- Added bomber lvl 2, with chemical weapon, also with stealth
  9. -- Added kamikaze ship, explodes when near enemy ships
  10. -- Added decrafter, a ship that tries to assimilate, but mostly destroys the obliterators
  11. -- Added deserted planet, also possible when changing planet's tmp to 1
  12. -- Added split fighter, tier 2 spacecraft, splits into 4 fighters when destroyed
  13. -- Added terraform ships, transform harsh terrain into their terrain
  14. -- No more opening settings menu! Just press the S button below the console button
  15. -- Technology! Press M to see research progress
  16. -- Messages about building obliterators and labs
  17. -- Statistics! Press T to see totals
  18. -- Fixed a misspell in the research (reserarch)
  19. PLANNED:
  20. -- Electromagnetic Pulse Area
  21. -- The Plague
  22. -- Split Bombers
  23. ]]--
  24. sim.gravityMode(1);
  25. sim.airMode(3);
  26. sim.edgeMode(2);
  27. local function settings(mousex, mousey, button, event)
  28.     tpt.drawrect(613, 97, 14, 14, 204, 204, 204)
  29.     tpt.fillrect(613, 97, 14, 14, 0, 0, 0, 255)
  30.     tpt.drawtext(618, 101, "S", 255, 255, 255, 255)
  31.     if tpt.mousex >= 613 and tpt.mousey >= 97 and tpt.mousex <= 627 and tpt.mousey <= 111 then
  32.         tpt.drawtext(499, 101, "Space Simulation, yay!", 0, 0, 255, 255)
  33.         tpt.drawrect(613, 97, 14, 14, 255, 255, 255)
  34.     end
  35.     if tpt.mousex >= 613 and tpt.mousey >= 97 and tpt.mousex <= 627 and tpt.mousey <= 111 then
  36.         if event == 1 then
  37.             sim.gravityMode(1);
  38.             sim.airMode(3);
  39.             sim.edgeMode(2);
  40.         end
  41.     end
  42. end
  43. tpt.register_mouseclick(settings)
  44. tpt.register_step(settings)
  45.  
  46. --Totals
  47. totallabs = 0
  48. totaldest = 0
  49. totalstolen = 0
  50. totalexpl = 0
  51. totalshipdest = 0
  52.  
  53. --Elements
  54. local continent;
  55. local ocean;
  56. local planet;
  57. local dplanet;
  58. local desert;
  59. local rock;
  60. local lasr;
  61. local city;
  62. local explosion;
  63. local missile;
  64. local ship;
  65. local bomber;
  66. local mothership;
  67. local builder;
  68. local decrafter;
  69. local nukeMissile;
  70. local kamikaze;
  71. local terraformer;
  72. local facility;
  73.  
  74. --Settings
  75. local explosionSpread = 0.5;
  76. local fighterLife = 1;
  77. local mothershipLife = 10;
  78. local destroyerLife = 20;
  79. local rTech = 0;
  80. local gTech = 0;
  81. local bTech = 0;
  82. local gdTech = 0;
  83. local wTech = 0;
  84. local gyTech = 0;
  85. local obliterators = 0;
  86. local splits = 0;
  87. local splitcreator;
  88.  
  89. local function keepInPercent()
  90.     if rTech > 20 then
  91.         rTech = rTech - 1
  92.     elseif gTech > 20 then
  93.         gTech = gTech - 1
  94.     elseif bTech > 20 then
  95.         bTech = bTech - 1
  96.     elseif gdTech > 20 then
  97.         gdTech = gdTech - 1
  98.     elseif wTech > 20 then
  99.         wTech = wTech - 1
  100.     elseif gyTech > 20 then
  101.         gyTech = gyTech - 1
  102.     end;
  103. end
  104. tpt.register_step(keepInPercent)
  105.  
  106. local function getFraction(tmp, big)
  107. -- Not for simulation, just for help
  108.     if big == 1 then
  109.         if tmp == 0 then
  110.             return "Red"
  111.         elseif tmp == 1 then
  112.             return "Green"
  113.         elseif tmp == 2 then
  114.             return "Blue"
  115.         elseif tmp == 3 then
  116.             return "Golden"
  117.         elseif tmp == 4 then
  118.             return "White"
  119.         elseif tmp == 5 then
  120.             return "Gray"
  121.         end
  122.      elseif big == 0 then
  123.         if tmp == 0 then
  124.             return "red"
  125.         elseif tmp == 1 then
  126.             return "green"
  127.         elseif tmp == 2 then
  128.             return "blue"
  129.         elseif tmp == 3 then
  130.             return "golden"
  131.         elseif tmp == 4 then
  132.             return "white"
  133.         elseif tmp == 5 then
  134.             return "gray"
  135.         end
  136.     end
  137. end
  138.  
  139. local R = 0
  140. local G = 0
  141. local B = 0
  142. local GD = 0
  143. local W = 0
  144. local GY = 0
  145. local function inform()
  146.     if rTech == 20 and R == 0 then
  147.         print("Red: Technology tier 2 acquired!");
  148.         R = 1
  149.     elseif gTech == 20 and G == 0 then
  150.         print("Green: Technology tier 2 acquired!");
  151.         G = 1
  152.     elseif bTech == 20 and B == 0 then
  153.         print("Blue: Technology tier 2 acquired!");
  154.         B = 1
  155.     elseif gdTech == 20 and GD == 0 then
  156.         print("Golden: Technology tier 2 acquired!");
  157.         GD = 1
  158.     elseif wTech == 20 and W == 0 then
  159.         print("White: Technology tier 2 acquired!");
  160.         W = 1
  161.     elseif gyTech == 20 and GY == 0 then
  162.         print("Gray: Technology tier 2 acquired!");
  163.         GY = 1
  164.     end;
  165.     if rTech >= 10 and gTech >= 10 and bTech >= 10 and gdTech >= 10 and wTech >= 10 and gyTech >= 10 and obliterators == 0 then
  166.         print('WARNING: Obliterator cannon deployment has begun!');
  167.         obliterators = 1
  168.     end
  169. end
  170. tpt.register_step(inform)
  171.  
  172. --Desert
  173. desert = elements.allocate("JosephMA", "DSRT");
  174. elements.element(desert, elements.element(elements.DEFAULT_PT_SAND));
  175. elements.property(desert, "HighTemperature", 673.15);
  176. elements.property(desert, "HighTemperatureTransition", elements.DEFAULT_PT_LAVA);
  177. elements.property(desert, "Name", "DSRT");
  178. elements.property(desert, "Description", "Deserts, barren sandy lands.");
  179. elements.property(desert, "MenuSection", 15);
  180.  
  181. --Rock
  182. rock = elements.allocate("JosephMA", "ROCK");
  183. elements.element(rock, elements.element(elements.DEFAULT_PT_BRCK));
  184. elements.property(rock, "HighTemperature", 873.15);
  185. elements.property(rock, "HighTemperatureTransition", elements.DEFAULT_PT_LAVA);
  186. elements.property(rock, "Name", "ROCK");
  187. elements.property(rock, "Description", "Rocks, stony and rocky.");
  188. elements.property(rock, "MenuSection", 15);
  189.  
  190. --City
  191. city = elements.allocate("JosephMA", "CITY");
  192. elements.element(city, elements.element(elements.DEFAULT_PT_BRCK));
  193. elements.property(city, "Color", 0xFF505070);
  194. elements.property(city, "HighTemperature", 873.15);
  195. elements.property(city, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  196. elements.property(city, "Name", "CITY");
  197. elements.property(city, "Description", "A city. People live here.");
  198. elements.property(city, "MenuSection", 15);
  199.  
  200. local function cityUpdate(i, x, y, s, n)
  201.     if sim.partProperty(i, "tmp2") == 0 then
  202.         sim.partProperty(i, "tmp", math.random(0, 5));
  203.         sim.partProperty(i, "tmp2", 1);
  204.     end
  205.     if math.random(1, 500) == 1 then
  206.         local part;
  207.         if math.random(1, 1000) == 1 then
  208.             if sim.partProperty(i, "tmp") == 0 and rTech == 20 then
  209.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), destroyer)
  210.                 print("Red: Released a destroyer spaceship!")
  211.                             totaldest = totaldest + 1
  212.                         elseif sim.partProperty(i, "tmp") == 1 and gTech == 20 then
  213.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), destroyer)
  214.                 print("Green: Released a destroyer spaceship!")
  215.                             totaldest = totaldest + 1
  216.                         elseif sim.partProperty(i, "tmp") == 2 and bTech == 20 then
  217.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), destroyer)
  218.                 print("Blue: Released a destroyer spaceship!")
  219.                             totaldest = totaldest + 1
  220.                         elseif sim.partProperty(i, "tmp") == 3 and gdTech == 20 then
  221.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), destroyer)
  222.                 print("Golden: Released a destroyer spaceship!")
  223.                             totaldest = totaldest + 1
  224.                         elseif sim.partProperty(i, "tmp") == 4 and wTech == 20 then
  225.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), destroyer)
  226.                 print("White: Released a destroyer spaceship!")
  227.                             totaldest = totaldest + 1
  228.                         elseif sim.partProperty(i, "tmp") == 5 and gyTech == 20 then
  229.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), destroyer)
  230.                 print("Gray: Released a destroyer spaceship!")
  231.                             totaldest = totaldest + 1
  232.             else
  233.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), elem.DEFAULT_PT_NONE)
  234.                         end
  235.             elseif math.random(1, 200) == 1 then
  236.                         if sim.partProperty(i, "tmp") == 0 and rTech == 20 then
  237.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), mothership)
  238.                         elseif sim.partProperty(i, "tmp") == 1 and gTech == 20 then
  239.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), mothership)
  240.                         elseif sim.partProperty(i, "tmp") == 2 and bTech == 20 then
  241.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), mothership)
  242.                         elseif sim.partProperty(i, "tmp") == 3 and gdTech == 20 then
  243.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), mothership)
  244.                         elseif sim.partProperty(i, "tmp") == 4 and wTech == 20 then
  245.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), mothership)
  246.                         elseif sim.partProperty(i, "tmp") == 5 and gyTech == 20 then
  247.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), mothership)
  248.             else
  249.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), elem.DEFAULT_PT_NONE)
  250.                         end
  251.             elseif math.random(1, 200) == 1 then
  252.                         if sim.partProperty(i, "tmp") == 0 and rTech == 20 then
  253.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), terraformer)
  254.                         elseif sim.partProperty(i, "tmp") == 1 and gTech == 20 then
  255.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), terraformer)
  256.                         elseif sim.partProperty(i, "tmp") == 2 and bTech == 20 then
  257.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), terraformer)
  258.                         elseif sim.partProperty(i, "tmp") == 3 and gdTech == 20 then
  259.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), terraformer)
  260.                         elseif sim.partProperty(i, "tmp") == 4 and wTech == 20 then
  261.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), terraformer)
  262.                         elseif sim.partProperty(i, "tmp") == 5 and gyTech == 20 then
  263.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), terraformer)
  264.             else
  265.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), elem.DEFAULT_PT_NONE)
  266.                         end
  267.             elseif math.random(1, 2) == 1 then
  268.                         local rand2 = math.random(1, 2)
  269.                         if sim.partProperty(i, "tmp") == 0 and rTech == 20 then
  270.                             if rand2 == 1 then
  271.                     part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), ship2)
  272.                             else
  273.                     part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), splitship)
  274.                             end
  275.                         elseif sim.partProperty(i, "tmp") == 1 and gTech == 20 then
  276.                             if rand2 == 1 then
  277.                     part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), ship2)
  278.                             else
  279.                     part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), splitship)
  280.                             end
  281.                         elseif sim.partProperty(i, "tmp") == 2 and bTech == 20 then
  282.                             if rand2 == 1 then
  283.                     part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), ship2)
  284.                             else
  285.                     part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), splitship)
  286.                             end
  287.                         elseif sim.partProperty(i, "tmp") == 3 and gdTech == 20 then
  288.                             if rand2 == 1 then
  289.                     part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), ship2)
  290.                             else
  291.                     part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), splitship)
  292.                             end
  293.                         elseif sim.partProperty(i, "tmp") == 4 and wTech == 20 then
  294.                             if rand2 == 1 then
  295.                     part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), ship2)
  296.                             else
  297.                     part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), splitship)
  298.                             end
  299.                         elseif sim.partProperty(i, "tmp") == 5 and gyTech == 20 then
  300.                             if rand2 == 1 then
  301.                     part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), ship2)
  302.                             else
  303.                     part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), splitship)
  304.                             end
  305.                         else
  306.                             part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), ship)
  307.             end
  308.             elseif math.random(1, 2) == 1 then
  309.                         if sim.partProperty(i, "tmp") == 0 and rTech == 20 then
  310.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), bomber2)
  311.                         elseif sim.partProperty(i, "tmp") == 1 and gTech == 20 then
  312.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), bomber2)
  313.                         elseif sim.partProperty(i, "tmp") == 2 and bTech == 20 then
  314.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), bomber2)
  315.                         elseif sim.partProperty(i, "tmp") == 3 and gdTech == 20 then
  316.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), bomber2)
  317.                         elseif sim.partProperty(i, "tmp") == 4 and wTech == 20 then
  318.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), bomber2)
  319.                         elseif sim.partProperty(i, "tmp") == 5 and gyTech == 20 then
  320.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), bomber2)
  321.                         else
  322.                             part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), bomber)
  323.             end
  324.                 elseif math.random(1, 2) == 1 then
  325.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), kamikaze);
  326.                 elseif math.random(1, 100) == 1 then
  327.                         if sim.partProperty(i, "tmp") == 0 and rTech == 20 and obliterators == 1 then
  328.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), decrafter)
  329.                         elseif sim.partProperty(i, "tmp") == 1 and gTech == 20 and obliterators == 1 then
  330.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), decrafter)
  331.                         elseif sim.partProperty(i, "tmp") == 2 and bTech == 20 and obliterators == 1 then
  332.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), decrafter)
  333.                         elseif sim.partProperty(i, "tmp") == 3 and gdTech == 20 and obliterators == 1 then
  334.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), decrafter)
  335.                         elseif sim.partProperty(i, "tmp") == 4 and wTech == 20 and obliterators == 1 then
  336.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), decrafter)
  337.                         elseif sim.partProperty(i, "tmp") == 5 and gyTech == 20 and obliterators == 1 then
  338.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), decrafter)
  339.             else
  340.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), elem.DEFAULT_PT_NONE)
  341.                         end
  342.                 else
  343.                         if sim.partProperty(i, "tmp") == 0 and rTech == 20 then
  344.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), builder2)
  345.                         elseif sim.partProperty(i, "tmp") == 1 and gTech == 20 then
  346.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), builder2)
  347.                         elseif sim.partProperty(i, "tmp") == 2 and bTech == 20 then
  348.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), builder2)
  349.                         elseif sim.partProperty(i, "tmp") == 3 and gdTech == 20 then
  350.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), builder2)
  351.                         elseif sim.partProperty(i, "tmp") == 4 and wTech == 20 then
  352.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), builder2)
  353.                         elseif sim.partProperty(i, "tmp") == 5 and gyTech == 20 then
  354.                 part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), builder2)
  355.                         else
  356.                             part = sim.partCreate(-1, x + math.random(-25, 25), y + math.random(-25, 25), builder)
  357.                         end
  358.             end;
  359.             sim.partProperty(part, "tmp", sim.partProperty(i, "tmp"));
  360.     end
  361. end
  362.  
  363. elements.property(city, "Update", cityUpdate);
  364.  
  365. --Continent
  366. continent = elements.allocate("JosephMA", "CONT");
  367. elements.element(continent, elements.element(elements.DEFAULT_PT_PLNT));
  368. elements.property(continent, "HighTemperature", 473.15);
  369. elements.property(continent, "HighTemperatureTransition", rock);
  370. elements.property(continent, "Name", "CONT");
  371. elements.property(continent, "Description", "Continent makes up planets.");
  372. elements.property(continent, "MenuSection", 15);
  373.  
  374. local function continentUpdate(i, x, y, s, n)
  375.     local life = sim.partProperty(i, "life");
  376.     if life > 0 then
  377.         for r in sim.neighbors(x,y,1,1) do
  378.             if math.random(1, 8) == 1 and sim.partProperty(r, "type") == ocean then
  379.                 sim.partChangeType(r, continent);
  380.                 sim.partProperty(r, "life", life - 1);
  381.             end
  382.         end
  383.     elseif math.random(1, 100000000) == 1 then
  384.         for r in sim.neighbors(x,y,1,1) do
  385.             if sim.partProperty(r, "type") == city then
  386.                 sim.partProperty(i, "tmp", sim.partProperty(r, "tmp"));
  387.                 sim.partProperty(i, "tmp2", sim.partProperty(r, "tmp2"));
  388.                 break;
  389.             end
  390.         end
  391.         sim.partChangeType(i, city);
  392.     end
  393. end
  394.  
  395. elements.property(continent, "Update", continentUpdate);
  396.  
  397. --Ocean
  398. ocean = elements.allocate("JosephMA", "OCEN");
  399. elements.element(ocean, elements.element(elements.DEFAULT_PT_WATR));
  400. elements.property(ocean, "HighTemperature", 473.15);
  401. elements.property(ocean, "HighTemperatureTransition", desert);
  402. elements.property(ocean, "Name", "OCEN");
  403. elements.property(ocean, "Description", "Oceans able to substain life on planets.");
  404. elements.property(ocean, "MenuSection", 15);
  405.  
  406. --Planet
  407. planet = elements.allocate("JosephMA", "PLNE");
  408. elements.element(planet, elements.element(elements.DEFAULT_PT_DMND));
  409. elements.property(planet, "Name", "PLNE");
  410. elements.property(planet, "Description", "Creates a randomized planet.");
  411.  
  412. --Deserted planet
  413. dplanet = elements.allocate("JosephMA", "DPLN");
  414. elements.element(dplanet, elements.element(elements.DEFAULT_PT_DMND));
  415. elements.property(dplanet, "Name", "DPLN");
  416. elements.property(dplanet, "Description", "A deserted globe.");
  417.  
  418. --Laser
  419. laser = elements.allocate("JosephMA", "LASR");
  420. elements.element(laser, elements.element(elements.DEFAULT_PT_PHOT));
  421. elements.property(laser, "Name", "LASR");
  422. elements.property(laser, "Temperature", 295.15);
  423. elements.property(laser, "Description", "Lasers, shoot everything up!");
  424. elements.property(laser, "MenuSection", 15);
  425.  
  426. --Void ray
  427. void = elements.allocate("JosephMA", "VRAY");
  428. elements.element(void, elements.element(elements.DEFAULT_PT_PHOT));
  429. elements.property(void, "Name", "VRAY");
  430. elements.property(void, "Temperature", 1275.15);
  431. elements.property(void, "Flammable", 9999)
  432. elements.property(void, "Explosive", 1)
  433. elements.property(void, "Description", "Void rays, blow everything... out!");
  434. elements.property(void, "MenuSection", 15);
  435.  
  436. --Explosion
  437. explosion = elements.allocate("JosephMA", "EXPL");
  438. elements.element(explosion, elements.element(elements.DEFAULT_PT_DUST));
  439. elements.property(explosion, "Name", "EXPL");
  440. elements.property(explosion, "Temperature", 673.15);
  441. elements.property(explosion, "Description", "Explosions, boom!");
  442. elements.property(explosion, "MenuSection", elem.SC_EXPLOSIVE);
  443.  
  444. local function explosionUpdate(i, x, y, s, n)
  445.     --Spawn explosion
  446.     local temp = tpt.get_property("temp", i);
  447.     local life = tpt.get_property("life", i);
  448.     local spread;
  449.    
  450.     if life == 0 then
  451.         spread = explosionSpread;
  452.     else
  453.         spread = life;
  454.     end
  455.    
  456.     sim.partKill(x - 1, y);
  457.     sim.partKill(x + 1, y);
  458.     sim.partKill(x - 2, y);
  459.     sim.partKill(x + 2, y);
  460.     sim.partKill(x, y - 1);
  461.     sim.partKill(x, y + 1);
  462.     sim.partKill(x, y - 2);
  463.     sim.partKill(x, y + 2);
  464.     sim.partKill(x - 1, y - 1);
  465.     sim.partKill(x + 1, y - 1);
  466.     sim.partKill(x - 1, y + 1);
  467.     sim.partKill(x + 1, y + 1);
  468.    
  469.     for t=0, 50, 1
  470.     do
  471.         local part = sim.partCreate(-3, x, y, elements.DEFAULT_PT_EMBR);
  472.         tpt.set_property("temp", temp, part);
  473.         tpt.set_property("life", math.random() * 100, part);
  474.         local angle = math.random() * 2.0 * math.pi/spread;
  475.         local v = (math.random()) * 5.0/spread;
  476.         tpt.set_property("vx", v * math.cos(angle), part);
  477.         tpt.set_property("vy", v * math.sin(angle), part);
  478.     end
  479.    
  480.     sim.partKill(i);
  481.     return 1;
  482. end
  483.  
  484. elements.property(explosion, "Update", explosionUpdate);
  485.  
  486. --Missile
  487. missile = elements.allocate("JosephMA", "MISL");
  488. elements.element(missile, elements.element(elements.DEFAULT_PT_PROT));
  489. elements.property(missile, "Name", "MISL");
  490. elements.property(missile, "Colour", 0x5D5D5C);
  491. elements.property(missile, "Description", "Explodes after a set life time!");
  492. elements.property(missile, "MenuSection", 15);
  493.  
  494. local function missileUpdate(i, x, y, s, n)
  495.     sim.partProperty(i, "life", sim.partProperty(i, "life") - 1);
  496.     if sim.partProperty(i, "life") <= 0 then
  497.         local part = sim.partCreate(-1, x, y, explosion);
  498.         sim.partProperty(part, "life", 1);
  499.         sim.partKill(i);
  500.                 totalexpl = totalexpl + 1
  501.         return 1;
  502.     end
  503.     --Smoke Trail
  504.     local part = sim.partCreate(-1, x, y, elements.DEFAULT_PT_SMKE);
  505.     sim.partProperty(part, "life", 20);
  506. end
  507.  
  508. elements.property(missile, "Update", missileUpdate);
  509.  
  510. --Chemical weapon
  511. chema = elements.allocate("JosephMA", "CHEM");
  512. elements.element(chema, elements.element(elements.DEFAULT_PT_PROT));
  513. elements.property(chema, "Name", "CHEM");
  514. elements.property(chema, "Colour", 0x5D5D5C);
  515. elements.property(chema, "Description", "Chemical weapon! Releases toxic and caustic gas, explodes after setting life time.");
  516. elements.property(chema, "MenuSection", 15);
  517.  
  518. local function chemaUpdate(i, x, y, s, n)
  519.     sim.partProperty(i, "life", sim.partProperty(i, "life") - 1);
  520.     if sim.partProperty(i, "life") <= 0 then
  521.         local part = sim.partCreate(-1, x, y, explosion);
  522.         sim.partProperty(part, "life", 1);
  523.         sim.partKill(i);
  524.                 totalexpl = totalexpl + 1
  525.         return 1;
  526.     end
  527.     --Toxic Trail
  528.     local part = sim.partCreate(-1, x, y, elements.DEFAULT_PT_CAUS);
  529.     sim.partProperty(part, "life", 20);
  530. end
  531.  
  532. elements.property(chema, "Update", chemaUpdate);
  533.  
  534. --Ship
  535. ship = elements.allocate("JosephMA", "SHIP");
  536. elements.element(ship, elements.element(elements.DEFAULT_PT_PROT));
  537. elements.property(ship, "HighTemperature", 1273.15);
  538. elements.property(ship, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  539. elements.property(ship, "Name", "SHIP");
  540. elements.property(ship, "Description", "Spacecraft fighter shoots lasers.");
  541. elements.property(ship, "MenuSection", elem.SC_SPECIAL);
  542.  
  543. local function shipUpdate(i, x, y, s, n)
  544.     --tmp is current team
  545.     local life = tpt.get_property("life", i);
  546.     if life == 0 then
  547.         tpt.set_property("life", fighterLife, i);
  548.         life = fighterLife;
  549.     end
  550.     local rand = math.random(1, 150);
  551.     if rand <= 75 then
  552.         for r in sim.neighbors(x,y,1,1) do
  553.             local partType = sim.partProperty(r, "type");
  554.             if partType == laser and sim.partProperty(r, "tmp") ~= tpt.get_property("tmp", i) then
  555.                 sim.partKill(r);
  556.                 tpt.set_property("life", life - 1, i);
  557.                 life = life - 1;
  558.                 if life - 1 <= -1 then
  559.                     sim.partKill(i);
  560.                                         totalshipdest = totalshipdest + 1
  561.                     return 1;
  562.                 end
  563.             elseif partType == explosion or partType == elements.DEFAULT_PT_EMBR then
  564.                 sim.partKill(i);
  565.                                 totalshipdest = totalshipdest + 1
  566.                 return 1;
  567.             end
  568.         end
  569.     end
  570.     --Movement
  571.     if math.random(1, 100) == 1 then
  572.         if math.random(1, 2) == 1 then
  573.             tpt.set_property("vx", math.random(-3, 3), i);
  574.         else
  575.             tpt.set_property("vy", math.random(-3, 3), i);
  576.         end
  577.     end
  578.     --Shooting
  579.     if rand == 1 then
  580.         for r in sim.neighbors(x,y,5,5) do
  581.             local partType = sim.partProperty(r, "type");
  582.             local tmp = tpt.get_property("tmp", i);
  583.             if (partType == ship or partType == bomber or partType == city or partType == mothership or partType == destroyer or partType == builder or partType == lab) and sim.partProperty(r, "tmp") ~= tmp then
  584.                 local part = sim.partCreate(-3, x, y, laser);
  585.                 tpt.set_property("vx", sim.partProperty(r, "x") - x, part);
  586.                 tpt.set_property("vy", sim.partProperty(r, "y") - y, part);
  587.                 tpt.set_property("tmp", tmp, part);
  588.                 tpt.set_property("life", 20, part);
  589.             end
  590.         end
  591.     end
  592. end
  593.  
  594. elements.property(ship, "Update", shipUpdate);
  595.  
  596. local function shipGraphics(i, colr, colg, colb)
  597.     local r;
  598.     local g;
  599.     local b;
  600.     local tmp = tpt.get_property("tmp", i);
  601.     if tmp == 0 then
  602.         r = 255;
  603.         g = 0;
  604.         b = 0;
  605.     elseif tmp == 1 then
  606.         r = 0;
  607.         g = 255;
  608.         b = 0;
  609.     elseif tmp == 2 then
  610.         r = 0;
  611.         g = 0;
  612.         b = 255;
  613.     elseif tmp == 3 then
  614.         r = 255;
  615.         g = 204;
  616.         b = 0;
  617.     elseif tmp == 4 then
  618.         r = 255;
  619.         g = 255;
  620.         b = 255;
  621.     elseif tmp == 5 then
  622.         r = 153;
  623.         g = 153;
  624.         b = 153;
  625.     end
  626.     return 1,0x00000001,255,r,g,b,255,255,255,255;
  627. end
  628.  
  629. elements.property(ship, "Graphics", shipGraphics);
  630.  
  631.  
  632. --Split ship
  633. splitship = elements.allocate("JosephMA", "SSHP");
  634. elements.element(splitship, elements.element(elements.DEFAULT_PT_PROT));
  635. elements.property(splitship, "HighTemperature", 1273.15);
  636. elements.property(splitship, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  637. elements.property(splitship, "Name", "SSHP");
  638. elements.property(splitship, "Description", "Split fighter, when destroyed turns into 4 normal fighters.");
  639. elements.property(splitship, "MenuSection", elem.SC_SPECIAL);
  640.  
  641. local function splitshipUpdate(i, x, y, s, n)
  642.     --tmp is current team
  643.     local life = tpt.get_property("life", i);
  644.     if life == 0 then
  645.         tpt.set_property("life", fighterLife, i);
  646.         life = fighterLife;
  647.     end
  648.     local rand = math.random(1, 150);
  649.     if rand <= 75 then
  650.         for r in sim.neighbors(x,y,1,1) do
  651.             local partType = sim.partProperty(r, "type");
  652.             if partType == laser and sim.partProperty(r, "tmp") ~= tpt.get_property("tmp", i) then
  653.                 sim.partKill(r);
  654.                 tpt.set_property("life", life - 1, i);
  655.                 life = life - 1;
  656.                 if life - 1 <= -1 then
  657.                     sim.partKill(i);
  658.                                         totalshipdest = totalshipdest + 1
  659.                     return 1;
  660.                 end
  661.             elseif partType == explosion or partType == elements.DEFAULT_PT_EMBR then
  662.                                 local part
  663.                                 part = sim.partCreate(-1, x - 1, y - 1, ship)
  664.                                 tpt.set_property("tmp", tpt.get_property("tmp", i), part);
  665.                                 part = sim.partCreate(-1, x - 1, y + 1, ship)
  666.                                 tpt.set_property("tmp", tpt.get_property("tmp", i), part);
  667.                                 part = sim.partCreate(-1, x + 1, y - 1, ship)
  668.                                 tpt.set_property("tmp", tpt.get_property("tmp", i), part);
  669.                                 part = sim.partCreate(-1, x + 1, y + 1, ship)
  670.                                 tpt.set_property("tmp", tpt.get_property("tmp", i), part);
  671.                 sim.partKill(i);
  672.                                 totalshipdest = totalshipdest + 1
  673.                 return 1;
  674.             end
  675.         end
  676.     end
  677.     --Movement
  678.     if math.random(1, 100) == 1 then
  679.         if math.random(1, 2) == 1 then
  680.             tpt.set_property("vx", math.random(-3, 3), i);
  681.         else
  682.             tpt.set_property("vy", math.random(-3, 3), i);
  683.         end
  684.     end
  685.     --Shooting
  686.         local tmp = tpt.get_property("tmp", i);
  687.     if rand == 1 then
  688.         for r in sim.neighbors(x,y,5,5) do
  689.             local partType = sim.partProperty(r, "type");
  690.             if (partType == ship or partType == bomber or partType == city or partType == mothership or partType == destroyer or partType == builder or partType == lab) and sim.partProperty(r, "tmp") ~= tmp then
  691.                 local part = sim.partCreate(-3, x, y, laser);
  692.                 tpt.set_property("vx", sim.partProperty(r, "x") - x, part);
  693.                 tpt.set_property("vy", sim.partProperty(r, "y") - y, part);
  694.                 tpt.set_property("tmp", tmp, part);
  695.                 tpt.set_property("life", 20, part);
  696.             end
  697.         end
  698.     end
  699.         if splits == 0 then
  700.             print(getFraction(tmp, 1) .. ": The first split ship in history has been built!")
  701.             splitcreator = tmp
  702.             splits = 1
  703.         end
  704. end
  705.  
  706. elements.property(splitship, "Update", splitshipUpdate);
  707.  
  708. local function splitshipGraphics(i, colr, colg, colb)
  709.     local r;
  710.     local g;
  711.     local b;
  712.     local tmp = tpt.get_property("tmp", i);
  713.     if tmp == 0 then
  714.         r = 255;
  715.         g = 0;
  716.         b = 0;
  717.     elseif tmp == 1 then
  718.         r = 0;
  719.         g = 255;
  720.         b = 0;
  721.     elseif tmp == 2 then
  722.         r = 0;
  723.         g = 0;
  724.         b = 255;
  725.     elseif tmp == 3 then
  726.         r = 255;
  727.         g = 204;
  728.         b = 0;
  729.     elseif tmp == 4 then
  730.         r = 255;
  731.         g = 255;
  732.         b = 255;
  733.     elseif tmp == 5 then
  734.         r = 153;
  735.         g = 153;
  736.         b = 153;
  737.     end
  738.     return 1,0x00000001,255,r,g,b,255,255,255,255;
  739. end
  740.  
  741. elements.property(splitship, "Graphics", splitshipGraphics);
  742.  
  743. --Ship 2
  744. ship2 = elements.allocate("JosephMA", "SHIP2");
  745. elements.element(ship2, elements.element(elements.DEFAULT_PT_PROT));
  746. elements.property(ship2, "HighTemperature", 1273.15);
  747. elements.property(ship2, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  748. elements.property(ship2, "Name", "SHP2");
  749. elements.property(ship2, "Description", "Level 2 of spacecraft fighter, shoots with destructive void rays");
  750. elements.property(ship2, "MenuSection", elem.SC_SPECIAL);
  751.  
  752. local function shipUpdate2(i, x, y, s, n)
  753.     --tmp is current team
  754.     local life = tpt.get_property("life", i);
  755.     if life == 0 then
  756.         tpt.set_property("life", fighterLife, i);
  757.         life = fighterLife;
  758.     end
  759.     local rand = math.random(1, 150);
  760.     if rand <= 75 then
  761.         for r in sim.neighbors(x,y,1,1) do
  762.             local partType = sim.partProperty(r, "type");
  763.             if partType == laser and sim.partProperty(r, "tmp") ~= tpt.get_property("tmp", i) then
  764.                 sim.partKill(r);
  765.                 tpt.set_property("life", life - 1, i);
  766.                 life = life - 1;
  767.                 if life - 1 <= -1 then
  768.                     sim.partKill(i);
  769.                                         totalshipdest = totalshipdest + 1
  770.                     return 1;
  771.                 end
  772.             elseif partType == explosion or partType == elements.DEFAULT_PT_EMBR then
  773.                 sim.partKill(i);
  774.                                 totalshipdest = totalshipdest + 1
  775.                 return 1;
  776.             end
  777.         end
  778.     end
  779.     --Movement
  780.     if math.random(1, 100) == 1 then
  781.         if math.random(1, 2) == 1 then
  782.             tpt.set_property("vx", math.random(-3, 3), i);
  783.         else
  784.             tpt.set_property("vy", math.random(-3, 3), i);
  785.         end
  786.     end
  787.     --Shooting
  788.     if rand == 1 then
  789.         for r in sim.neighbors(x,y,5,5) do
  790.             local partType = sim.partProperty(r, "type");
  791.             local tmp = tpt.get_property("tmp", i);
  792.             if (partType == ship or partType == bomber or partType == city or partType == mothership or partType == destroyer or partType == builder or partType == ship2 or partType == bomber2 or partType == kamikaze or partType == decrafter) and sim.partProperty(r, "tmp") ~= tmp then
  793.                 local part = sim.partCreate(-3, x, y, void);
  794.                 tpt.set_property("vx", sim.partProperty(r, "x") - x, part);
  795.                 tpt.set_property("vy", sim.partProperty(r, "y") - y, part);
  796.                 tpt.set_property("tmp", tmp, part);
  797.                 tpt.set_property("life", 20, part);
  798.             end
  799.         end
  800.     end
  801. end
  802.  
  803. elements.property(ship2, "Update", shipUpdate2);
  804.  
  805. local function shipGraphics2(i, colr, colg, colb)
  806.     local r;
  807.     local g;
  808.     local b;
  809.     local tmp = tpt.get_property("tmp", i);
  810.     if tmp == 0 then
  811.         r = 255;
  812.         g = 0;
  813.         b = 0;
  814.     elseif tmp == 1 then
  815.         r = 0;
  816.         g = 255;
  817.         b = 0;
  818.     elseif tmp == 2 then
  819.         r = 0;
  820.         g = 0;
  821.         b = 255;
  822.     elseif tmp == 3 then
  823.         r = 255;
  824.         g = 204;
  825.         b = 0;
  826.     elseif tmp == 4 then
  827.         r = 255;
  828.         g = 255;
  829.         b = 255;
  830.     elseif tmp == 5 then
  831.         r = 153;
  832.         g = 153;
  833.         b = 153;
  834.     end
  835.     return 1,0x00000001,255,r,g,b,255,255,255,255;
  836. end
  837.  
  838. elements.property(ship2, "Graphics", shipGraphics2);
  839.  
  840. --Bomber
  841. bomber = elements.allocate("JosephMA", "BMBR");
  842. elements.element(bomber, elements.element(elements.DEFAULT_PT_PROT));
  843. elements.property(bomber, "HighTemperature", 1273.15);
  844. elements.property(bomber, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  845. elements.property(bomber, "Name", "BMBR");
  846. elements.property(bomber, "Description", "Spacecraft bomber shoots missiles.");
  847. elements.property(bomber, "MenuSection", elem.SC_SPECIAL);
  848.  
  849. local function bomberUpdate(i, x, y, s, n)
  850.     --tmp is current team
  851.     local life = tpt.get_property("life", i);
  852.     if life == 0 then
  853.         tpt.set_property("life", fighterLife, i);
  854.         life = fighterLife;
  855.     end
  856.     local rand = math.random(1, 150);
  857.     if rand <= 75 then
  858.         for r in sim.neighbors(x,y,1,1) do
  859.             local partType = sim.partProperty(r, "type");
  860.             if partType == laser and sim.partProperty(r, "tmp") ~= tpt.get_property("tmp", i) then
  861.                 sim.partKill(r);
  862.                 tpt.set_property("life", life - 1, i);
  863.                 life = life - 1;
  864.                 if life - 1 <= -1 then
  865.                     sim.partKill(i);
  866.                                         totalshipdest = totalshipdest + 1
  867.                     return 1;
  868.                 end
  869.             elseif partType == explosion or partType == elements.DEFAULT_PT_EMBR then
  870.                 sim.partKill(i);
  871.                                 totalshipdest = totalshipdest + 1
  872.                 return 1;
  873.             end
  874.         end
  875.     end
  876.     --Movement
  877.     if math.random(1, 100) == 1 then
  878.         if math.random(1, 2) == 1 then
  879.             tpt.set_property("vx", math.random(-1, 1), i);
  880.         else
  881.             tpt.set_property("vy", math.random(-1, 1), i);
  882.         end
  883.     end
  884.     --Shooting
  885.     if rand == 1 then
  886.         for r in sim.neighbors(x,y,5,5) do
  887.             local partType = sim.partProperty(r, "type");
  888.             local tmp = tpt.get_property("tmp", i);
  889.             if (partType == ship or partType == bomber or partType == city or partType == mothership or partType == destroyer or partType == builder or partType == kamikaze or partType == lab) and sim.partProperty(r, "tmp") ~= tmp then
  890.                 local part = sim.partCreate(-3, x, y, missile);
  891.                 tpt.set_property("vx", sim.partProperty(r, "x") - x, part);
  892.                 tpt.set_property("vy", sim.partProperty(r, "y") - y, part);
  893.                 tpt.set_property("life", 20, part);
  894.                 break;
  895.             end
  896.         end
  897.     end
  898. end
  899.  
  900. elements.property(bomber, "Update", bomberUpdate);
  901.  
  902. local function bomberGraphics(i, colr, colg, colb)
  903.     local r;
  904.     local g;
  905.     local b;
  906.     local tmp = tpt.get_property("tmp", i);
  907.     if tmp == 0 then
  908.         r = 255;
  909.         g = 0;
  910.         b = 0;
  911.     elseif tmp == 1 then
  912.         r = 0;
  913.         g = 255;
  914.         b = 0;
  915.     elseif tmp == 2 then
  916.         r = 0;
  917.         g = 0;
  918.         b = 255;
  919.     elseif tmp == 3 then
  920.         r = 255;
  921.         g = 204;
  922.         b = 0;
  923.     elseif tmp == 4 then
  924.         r = 255;
  925.         g = 255;
  926.         b = 255;
  927.     elseif tmp == 5 then
  928.         r = 153;
  929.         g = 153;
  930.         b = 153;
  931.     end
  932.     return 1,0x00000001,255,r,g,b,255,255,255,255;
  933. end
  934.  
  935. elements.property(bomber, "Graphics", bomberGraphics);
  936.  
  937. --Bomber 2
  938. bomber2 = elements.allocate("JosephMA", "BMBR2");
  939. elements.element(bomber2, elements.element(elements.DEFAULT_PT_PROT));
  940. elements.property(bomber2, "HighTemperature", 1273.15);
  941. elements.property(bomber2, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  942. elements.property(bomber2, "Name", "BMB2");
  943. elements.property(bomber2, "Description", "Level 2 of space bomber, has got chemical weapon onboard.");
  944. elements.property(bomber2, "Hardness", 0);
  945. elements.property(bomber2, "MenuSection", elem.SC_SPECIAL);
  946.  
  947. local function bomberUpdate2(i, x, y, s, n)
  948.     --tmp is current team
  949.     local life = tpt.get_property("life", i);
  950.     if life == 0 then
  951.         tpt.set_property("life", fighterLife, i);
  952.         life = fighterLife;
  953.     end
  954.     local rand = math.random(1, 150);
  955.     if rand <= 75 then
  956.         for r in sim.neighbors(x,y,1,1) do
  957.             local partType = sim.partProperty(r, "type");
  958.             if partType == laser and sim.partProperty(r, "tmp") ~= tpt.get_property("tmp", i) then
  959.                 sim.partKill(r);
  960.                 tpt.set_property("life", life - 1, i);
  961.                 life = life - 1;
  962.                 if life - 1 <= -1 then
  963.                     sim.partKill(i);
  964.                                         totalshipdest = totalshipdest + 1
  965.                     return 1;
  966.                 end
  967.             elseif partType == explosion or partType == elements.DEFAULT_PT_EMBR then
  968.                 sim.partKill(i);
  969.                                 totalshipdest = totalshipdest + 1
  970.                 return 1;
  971.             end
  972.         end
  973.     end
  974.     --Movement
  975.     if math.random(1, 100) == 1 then
  976.         if math.random(1, 2) == 1 then
  977.             tpt.set_property("vx", math.random(-1, 1), i);
  978.         else
  979.             tpt.set_property("vy", math.random(-1, 1), i);
  980.         end
  981.     end
  982.     --Shooting
  983.     if rand == 1 then
  984.         for r in sim.neighbors(x,y,5,5) do
  985.             local partType = sim.partProperty(r, "type");
  986.             local tmp = tpt.get_property("tmp", i);
  987.             if (partType == ship or partType == bomber or partType == city or partType == mothership or partType == destroyer or partType == builder or partType == kamikaze or partType == lab or partType == decrafter) and sim.partProperty(r, "tmp") ~= tmp then
  988.                 local part = sim.partCreate(-3, x, y, chema);
  989.                 tpt.set_property("vx", sim.partProperty(r, "x") - x, part);
  990.                 tpt.set_property("vy", sim.partProperty(r, "y") - y, part);
  991.                 tpt.set_property("life", 20, part);
  992.                 break;
  993.             end
  994.         end
  995.     end
  996. end
  997.  
  998. elements.property(bomber2, "Update", bomberUpdate2);
  999.  
  1000. local function bomberGraphics2(i, colr, colg, colb)
  1001.     local r;
  1002.     local g;
  1003.     local b;
  1004.     local tmp = tpt.get_property("tmp", i);
  1005.     if tmp == 0 then
  1006.         r = 255;
  1007.         g = 0;
  1008.         b = 0;
  1009.     elseif tmp == 1 then
  1010.         r = 0;
  1011.         g = 255;
  1012.         b = 0;
  1013.     elseif tmp == 2 then
  1014.         r = 0;
  1015.         g = 0;
  1016.         b = 255;
  1017.     elseif tmp == 3 then
  1018.         r = 255;
  1019.         g = 204;
  1020.         b = 0;
  1021.     elseif tmp == 4 then
  1022.         r = 255;
  1023.         g = 255;
  1024.         b = 255;
  1025.     elseif tmp == 5 then
  1026.         r = 153;
  1027.         g = 153;
  1028.         b = 153;
  1029.     end
  1030.     return 1,0x00000001,255,r,g,b,255,255,255,255;
  1031. end
  1032.  
  1033. elements.property(bomber2, "Graphics", bomberGraphics2);
  1034.  
  1035. --Mothership
  1036. mothership = elements.allocate("JosephMA", "MOTH");
  1037. elements.element(mothership, elements.element(elements.DEFAULT_PT_PROT));
  1038. elements.property(mothership, "HighTemperature", 1273.15);
  1039. elements.property(mothership, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  1040. elements.property(mothership, "Name", "MOTH");
  1041. elements.property(mothership, "Description", "Mothership produces ships and fires fast! Also has nukes onboard");
  1042. elements.property(mothership, "MenuSection", elem.SC_SPECIAL);
  1043.  
  1044. local function mothershipUpdate(i, x, y, s, n)
  1045.     --tmp is current team
  1046.     local life = tpt.get_property("life", i);
  1047.     if life == 0 then
  1048.         tpt.set_property("life", mothershipLife, i);
  1049.         life = mothershipLife;
  1050.     end
  1051.     local rand = math.random(1, 60);
  1052.     if rand <= 30 then
  1053.         for r in sim.neighbors(x,y,1,1) do
  1054.             local partType = sim.partProperty(r, "type");
  1055.             if partType == laser and sim.partProperty(r, "tmp") ~= tpt.get_property("tmp", i) then
  1056.                 sim.partKill(r);
  1057.                 tpt.set_property("life", life - 1, i);
  1058.                 life = life - 1;
  1059.                 if life - 1 <= -1 then
  1060.                     sim.partKill(i);
  1061.                                         totalshipdest = totalshipdest + 1
  1062.                     return 1;
  1063.                 end
  1064.             elseif partType == explosion or partType == elements.DEFAULT_PT_EMBR then
  1065.                 tpt.set_property("life", life - 1, i);
  1066.                 if life - 1 <= -1 then
  1067.                     sim.partKill(i);
  1068.                                         totalshipdest = totalshipdest + 1
  1069.                     return 1;
  1070.                 end
  1071.             end
  1072.         end
  1073.     end
  1074.     --Movement
  1075.     if math.random(1, 100) == 1 then
  1076.         if math.random(1, 2) == 1 then
  1077.             tpt.set_property("vx", math.random(-1, 1), i);
  1078.         else
  1079.             tpt.set_property("vy", math.random(-1, 1), i);
  1080.         end
  1081.     end
  1082.     --Shooting
  1083.     if rand == 1 then
  1084.         for r in sim.neighbors(x,y,10,10) do
  1085.             local partType = sim.partProperty(r, "type");
  1086.             local tmp = tpt.get_property("tmp", i);
  1087.             if (partType == ship or partType == bomber or partType == city or partType == mothership or partType == destroyer or partType == builder or partType == kamikaze or partType == lab or partType == decrafter) and sim.partProperty(r, "tmp") ~= tmp then
  1088.                 if partType ~= city then
  1089.                     local part = sim.partCreate(-3, x, y, laser);
  1090.                     tpt.set_property("vx", sim.partProperty(r, "x") - x, part);
  1091.                     tpt.set_property("vy", sim.partProperty(r, "y") - y, part);
  1092.                     tpt.set_property("tmp", tmp, part);
  1093.                     tpt.set_property("life", 20, part);
  1094.                     part = sim.partCreate(-3, x - 1, y, laser);
  1095.                     tpt.set_property("vx", sim.partProperty(r, "x") - x, part);
  1096.                     tpt.set_property("vy", sim.partProperty(r, "y") - y, part);
  1097.                     tpt.set_property("tmp", tmp, part);
  1098.                     tpt.set_property("life", 20, part);
  1099.                     part = sim.partCreate(-3, x + 1, y, laser);
  1100.                     tpt.set_property("vx", sim.partProperty(r, "x") - x, part);
  1101.                     tpt.set_property("vy", sim.partProperty(r, "y") - y, part);
  1102.                     tpt.set_property("tmp", tmp, part);
  1103.                     tpt.set_property("life", 20, part);
  1104.                     part = sim.partCreate(-3, x, y - 1, laser);
  1105.                     tpt.set_property("vx", sim.partProperty(r, "x") - x, part);
  1106.                     tpt.set_property("vy", sim.partProperty(r, "y") - y, part);
  1107.                     tpt.set_property("tmp", tmp, part);
  1108.                     tpt.set_property("life", 20, part);
  1109.                     part = sim.partCreate(-3, x, y + 1, laser);
  1110.                     tpt.set_property("vx", sim.partProperty(r, "x") - x, part);
  1111.                     tpt.set_property("vy", sim.partProperty(r, "y") - y, part);
  1112.                     tpt.set_property("tmp", tmp, part);
  1113.                     tpt.set_property("life", 20, part);
  1114.                                 elseif (partType == obliteratorCannon) and sim.partProperty(r, "tmp") ~= tmp then
  1115.                                     local part;
  1116.                                     part = sim.partCreate(-3, x, y, decrafter);
  1117.                                     sim.partProperty(part, "tmp", sim.partProperty(i, "tmp"));
  1118.                 else
  1119.                     --Destroy or assimilate
  1120.                     if math.random(1, 2) == 1 then
  1121.                         --sim.partChangeType(r, elements.DEFAULT_PT_BOMB);
  1122.                         sim.partChangeType(r, rock);
  1123.                     else
  1124.                         sim.partProperty(r, "tmp", tmp)
  1125.                     end
  1126.                 end
  1127.             end
  1128.         end
  1129.     end
  1130.     --Create more ships
  1131.     if math.random(1, 300) == 1 then
  1132.         local part;
  1133.         if math.random(1, 2) == 1 then
  1134.             part = sim.partCreate(-3, x, y, ship);
  1135.         else
  1136.             part = sim.partCreate(-3, x , y, bomber);
  1137.         end
  1138.         sim.partProperty(part, "tmp", sim.partProperty(i, "tmp"));
  1139.     end
  1140. end
  1141.  
  1142. elements.property(mothership, "Update", mothershipUpdate);
  1143.  
  1144. local function mothershipGraphics(i, colr, colg, colb)
  1145.     local r;
  1146.     local g;
  1147.     local b;
  1148.     local tmp = tpt.get_property("tmp", i);
  1149.     if tmp == 0 then
  1150.         r = 255;
  1151.         g = 0;
  1152.         b = 0;
  1153.     elseif tmp == 1 then
  1154.         r = 0;
  1155.         g = 255;
  1156.         b = 0;
  1157.     elseif tmp == 2 then
  1158.         r = 0;
  1159.         g = 0;
  1160.         b = 255;
  1161.     elseif tmp == 3 then
  1162.         r = 255;
  1163.         g = 204;
  1164.         b = 0;
  1165.     elseif tmp == 4 then
  1166.         r = 255;
  1167.         g = 255;
  1168.         b = 255;
  1169.     elseif tmp == 5 then
  1170.         r = 153;
  1171.         g = 153;
  1172.         b = 153;
  1173.     end
  1174.     local x = tpt.get_property("x",i);
  1175.     local y = tpt.get_property("y",i);
  1176.     graphics.fillRect(x - 2, y - 2, 5, 5, r, g, b);
  1177. end
  1178.  
  1179. elements.property(mothership, "Graphics", mothershipGraphics);
  1180.  
  1181. --Destroyer
  1182. destroyer = elements.allocate("JosephMA", "DSTR");
  1183. elements.element(destroyer, elements.element(elements.DEFAULT_PT_PROT));
  1184. elements.property(destroyer, "HighTemperature", 1273.15);
  1185. elements.property(destroyer, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  1186. elements.property(destroyer, "Name", "DSTR");
  1187. elements.property(destroyer, "Description", "Destroys all worlds.");
  1188. elements.property(destroyer, "MenuSection", elem.SC_SPECIAL);
  1189.  
  1190. local function destroyerUpdate(i, x, y, s, n)
  1191.     --tmp is current team
  1192.     local life = tpt.get_property("life", i);
  1193.     if life == 0 then
  1194.         tpt.set_property("life", destroyerLife, i);
  1195.         life = destroyerLife;
  1196.     end
  1197.     local rand = math.random(1, 30);
  1198.     if rand <= 15 then
  1199.         for r in sim.neighbors(x,y,1,1) do
  1200.             local partType = sim.partProperty(r, "type");
  1201.             if partType == laser and sim.partProperty(r, "tmp") ~= tpt.get_property("tmp", i) then
  1202.                 sim.partKill(r);
  1203.                 tpt.set_property("life", life - 1, i);
  1204.                 life = life - 1;
  1205.                 if life - 1 <= -1 then
  1206.                     sim.partKill(i);
  1207.                                         totalshipdest = totalshipdest + 1
  1208.                     return 1;
  1209.                 end
  1210.             elseif partType == explosion or partType == elements.DEFAULT_PT_EMBR then
  1211.                 tpt.set_property("life", life - 1, i);
  1212.                 if life - 1 <= -1 then
  1213.                     sim.partKill(i);
  1214.                                         totalshipdest = totalshipdest + 1
  1215.                     return 1;
  1216.                 end
  1217.             end
  1218.         end
  1219.     end
  1220.     --Movement
  1221.     if math.random(1, 100) == 1 then
  1222.         if math.random(1, 2) == 1 then
  1223.             tpt.set_property("vx", math.random(-1, 1), i);
  1224.         else
  1225.             tpt.set_property("vy", math.random(-1, 1), i);
  1226.         end
  1227.     end
  1228.     --Shooting
  1229.     if rand == 1 then
  1230.         for r in sim.neighbors(x,y,10,10) do
  1231.             local partType = sim.partProperty(r, "type");
  1232.             local tmp = tpt.get_property("tmp", i);
  1233.             if (partType == ship or partType == bomber or partType == city or partType == mothership or partType == destroyer or partType == builder or partType == kamikaze or partType == lab or partType == decrafter) and sim.partProperty(r, "tmp") ~= tmp then
  1234.                 if partType ~= city then
  1235.                     --Nuke missile
  1236.                     local part = sim.partCreate(-3, x, y, nukeMissile);
  1237.                     tpt.set_property("vx", sim.partProperty(r, "x") - x, part);
  1238.                     tpt.set_property("vy", sim.partProperty(r, "y") - y, part);
  1239.                     --tpt.set_property("tmp", tmp, part);
  1240.                     tpt.set_property("life", 40, part);
  1241.                 else
  1242.                     --Destroy
  1243.                     if math.random(1, 2) == 1 then
  1244.                         --sim.partChangeType(r, elements.DEFAULT_PT_BOMB);
  1245.                         sim.partChangeType(r, rock);
  1246.                     end
  1247.                 end
  1248.             --[[elseif partType == ocean or partType == continent then
  1249.                 --Destroy
  1250.                 if math.random(1, 10) == 1 then
  1251.                     sim.partChangeType(r, elements.DEFAULT_PT_BOMB);
  1252.                 else
  1253.                     sim.partProperty(r, "temp", 2773.15);
  1254.                 end
  1255.             elseif partType == desert then
  1256.                 --Obliviate
  1257.                 sim.partChangeType(r, elements.DEFAULT_PT_PLSM);]]--
  1258.             end
  1259.         end
  1260.     end
  1261.     --Create more ships
  1262.     if math.random(1, 300) == 1 then
  1263.         local part;
  1264.         if math.random(1, 2) == 1 then
  1265.             part = sim.partCreate(-3, x, y, ship);
  1266.         else
  1267.             part = sim.partCreate(-3, x , y, bomber);
  1268.         end
  1269.         sim.partProperty(part, "tmp", sim.partProperty(i, "tmp"));
  1270.     end
  1271. end
  1272.  
  1273. elements.property(destroyer, "Update", destroyerUpdate);
  1274.  
  1275. local function destroyerGraphics(i, colr, colg, colb)
  1276.     local r;
  1277.     local g;
  1278.     local b;
  1279.     local tmp = tpt.get_property("tmp", i);
  1280.     if tmp == 0 then
  1281.         r = 255;
  1282.         g = 0;
  1283.         b = 0;
  1284.     elseif tmp == 1 then
  1285.         r = 0;
  1286.         g = 255;
  1287.         b = 0;
  1288.     elseif tmp == 2 then
  1289.         r = 0;
  1290.         g = 0;
  1291.         b = 255;
  1292.     elseif tmp == 3 then
  1293.         r = 255;
  1294.         g = 204;
  1295.         b = 0;
  1296.     elseif tmp == 4 then
  1297.         r = 255;
  1298.         g = 255;
  1299.         b = 255;
  1300.     elseif tmp == 5 then
  1301.         r = 153;
  1302.         g = 153;
  1303.         b = 153;
  1304.     end
  1305.     local x = tpt.get_property("x",i);
  1306.     local y = tpt.get_property("y",i);
  1307.     graphics.fillRect(x - 4, y - 4, 9, 9, r, g, b);
  1308. end
  1309.  
  1310. elements.property(destroyer, "Graphics", destroyerGraphics);
  1311.  
  1312. --Builder
  1313. builder = elements.allocate("JosephMA", "BLDR");
  1314. elements.element(builder, elements.element(elements.DEFAULT_PT_PROT));
  1315. elements.property(builder, "HighTemperature", 1273.15);
  1316. elements.property(builder, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  1317. elements.property(builder, "Name", "BLDR");
  1318. elements.property(builder, "Description", "Spacecraft builder builds space cities.");
  1319. elements.property(builder, "MenuSection", elem.SC_SPECIAL);
  1320.  
  1321. local function builderUpdate(i, x, y, s, n)
  1322.     --tmp is current team
  1323.     local life = tpt.get_property("life", i);
  1324.     if life == 0 then
  1325.         tpt.set_property("life", fighterLife, i);
  1326.         life = fighterLife;
  1327.     end
  1328.     --Damage
  1329.     if math.random(1, 2) == 1 then
  1330.         for r in sim.neighbors(x,y,1,1) do
  1331.             local partType = sim.partProperty(r, "type");
  1332.             if partType == laser and sim.partProperty(r, "tmp") ~= tpt.get_property("tmp", i) then
  1333.                 sim.partKill(r);
  1334.                 tpt.set_property("life", life - 1, i);
  1335.                 life = life - 1;
  1336.                 if life - 1 <= -1 then
  1337.                     sim.partKill(i);
  1338.                                         totalshipdest = totalshipdest + 1
  1339.                     return 1;
  1340.                 end
  1341.             elseif partType == explosion or partType == elements.DEFAULT_PT_EMBR then
  1342.                 sim.partKill(i);
  1343.                                 totalshipdest = totalshipdest + 1
  1344.                 return 1;
  1345.             end
  1346.         end
  1347.     end
  1348.     --Movement
  1349.     if math.random(1, 100) == 1 then
  1350.         if math.random(1, 2) == 1 then
  1351.             tpt.set_property("vx", math.random(-3, 3), i);
  1352.         else
  1353.             tpt.set_property("vy", math.random(-3, 3), i);
  1354.         end
  1355.     end
  1356.     --Create construction
  1357.     if math.random(1, 1000) == 1 then
  1358.                 local building = math.random(1, 100)
  1359.         --Lab
  1360.         if building <= 99 and building >= 85 then
  1361.             sim.partProperty(i, "tmp2", 1);
  1362.             sim.partChangeType(i, lab);
  1363.                     if sim.partProperty(i, "tmp") == 0 then
  1364.                         print("Red: Laboratory has been built!")
  1365.                     elseif sim.partProperty(i, "tmp") == 1 then
  1366.                         print("Green: Laboratory has been built!")
  1367.                     elseif sim.partProperty(i, "tmp") == 2 then
  1368.                         print("Blue: Laboratory has been built!")
  1369.                     elseif sim.partProperty(i, "tmp") == 3 then
  1370.                         print("Golden: Laboratory has been built!")
  1371.                     elseif sim.partProperty(i, "tmp") == 4 then
  1372.                         print("White: Laboratory has been built!")
  1373.                     elseif sim.partProperty(i, "tmp") == 5 then
  1374.                         print("Gray: Laboratory has been built!")
  1375.                     end
  1376.                     totallabs = totallabs + 1
  1377.             --City
  1378.                 elseif building < 90 then
  1379.             sim.partProperty(i, "tmp2", 1);
  1380.             sim.partChangeType(i, city);
  1381.         --Obliterator cannon
  1382.                 elseif building == 100 and rTech >= 10 and gTech >= 10 and bTech >= 10 and gdTech >= 10 and wTech >= 10 and gyTech >= 10 then
  1383.             sim.partChangeType(i, obliteratorCannon);
  1384.                     if sim.partProperty(i, "tmp") == 0 then
  1385.                         print("Red: Obliterator cannon has been built!")
  1386.                     elseif sim.partProperty(i, "tmp") == 1 then
  1387.                         print("Green: Obliterator cannon has been built!")
  1388.                     elseif sim.partProperty(i, "tmp") == 2 then
  1389.                         print("Blue: Obliterator cannon has been built!")
  1390.                     elseif sim.partProperty(i, "tmp") == 3 then
  1391.                         print("Golden: Obliterator cannon has been built!")
  1392.                     elseif sim.partProperty(i, "tmp") == 4 then
  1393.                         print("White: Obliterator cannon has been built!")
  1394.                     elseif sim.partProperty(i, "tmp") == 5 then
  1395.                         print("Gray: Obliterator cannon has been built!")
  1396.                     end
  1397.         end
  1398.     end
  1399. end
  1400.  
  1401. elements.property(builder, "Update", builderUpdate);
  1402.  
  1403. local function builderGraphics(i, colr, colg, colb)
  1404.     local r;
  1405.     local g;
  1406.     local b;
  1407.     local tmp = tpt.get_property("tmp", i);
  1408.     if tmp == 0 then
  1409.         r = 255;
  1410.         g = 0;
  1411.         b = 0;
  1412.     elseif tmp == 1 then
  1413.         r = 0;
  1414.         g = 255;
  1415.         b = 0;
  1416.     elseif tmp == 2 then
  1417.         r = 0;
  1418.         g = 0;
  1419.         b = 255;
  1420.     elseif tmp == 3 then
  1421.         r = 255;
  1422.         g = 204;
  1423.         b = 0;
  1424.     elseif tmp == 4 then
  1425.         r = 255;
  1426.         g = 255;
  1427.         b = 255;
  1428.     elseif tmp == 5 then
  1429.         r = 153;
  1430.         g = 153;
  1431.         b = 153;
  1432.     end
  1433.     return 1,0x00000001,255,r,g,b,255,255,255,255;
  1434. end
  1435.  
  1436. elements.property(builder, "Graphics", builderGraphics);
  1437.  
  1438. --Builder 2
  1439. builder2 = elements.allocate("JosephMA", "BLDR2");
  1440. elements.element(builder2, elements.element(elements.DEFAULT_PT_PROT));
  1441. elements.property(builder2, "HighTemperature", 1273.15);
  1442. elements.property(builder2, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  1443. elements.property(builder2, "Name", "BLD2");
  1444. elements.property(builder2, "Description", "Spacecraft builder builds obliterators more often.");
  1445. elements.property(builder2, "MenuSection", elem.SC_SPECIAL);
  1446.  
  1447. local function builder2Update(i, x, y, s, n)
  1448.     --tmp is current team
  1449.     local life = tpt.get_property("life", i);
  1450.     if life == 0 then
  1451.         tpt.set_property("life", fighterLife, i);
  1452.         life = fighterLife;
  1453.     end
  1454.     --Damage
  1455.     if math.random(1, 2) == 1 then
  1456.         for r in sim.neighbors(x,y,1,1) do
  1457.             local partType = sim.partProperty(r, "type");
  1458.             if partType == laser and sim.partProperty(r, "tmp") ~= tpt.get_property("tmp", i) then
  1459.                 sim.partKill(r);
  1460.                 tpt.set_property("life", life - 1, i);
  1461.                 life = life - 1;
  1462.                 if life - 1 <= -1 then
  1463.                     sim.partKill(i);
  1464.                                         totalshipdest = totalshipdest + 1
  1465.                     return 1;
  1466.                 end
  1467.             elseif partType == explosion or partType == elements.DEFAULT_PT_EMBR then
  1468.                 sim.partKill(i);
  1469.                                 totalshipdest = totalshipdest + 1
  1470.                 return 1;
  1471.             end
  1472.         end
  1473.     end
  1474.     --Movement
  1475.     if math.random(1, 100) == 1 then
  1476.         if math.random(1, 2) == 1 then
  1477.             tpt.set_property("vx", math.random(-3, 3), i);
  1478.         else
  1479.             tpt.set_property("vy", math.random(-3, 3), i);
  1480.         end
  1481.     end
  1482.     --Create construction
  1483.     if math.random(1, 1000) == 1 then
  1484.                 local building = math.random(1, 100)
  1485.             --City
  1486.                 if building < 97 then
  1487.             sim.partProperty(i, "tmp2", 1);
  1488.             sim.partChangeType(i, city);
  1489.         --Obliterator cannon
  1490.                 elseif building <= 100 and building >= 98 and rTech >= 10 and gTech >= 10 and bTech >= 10 and gdTech >= 10 and wTech >= 10 and gyTech >= 10 then
  1491.             sim.partChangeType(i, obliteratorCannon);
  1492.                     if sim.partProperty(i, "tmp") == 0 then
  1493.                         print("Red: Obliterator cannon has been built!")
  1494.                     elseif sim.partProperty(i, "tmp") == 1 then
  1495.                         print("Green: Obliterator cannon has been built!")
  1496.                     elseif sim.partProperty(i, "tmp") == 2 then
  1497.                         print("Blue: Obliterator cannon has been built!")
  1498.                     elseif sim.partProperty(i, "tmp") == 3 then
  1499.                         print("Golden: Obliterator cannon has been built!")
  1500.                     elseif sim.partProperty(i, "tmp") == 4 then
  1501.                         print("White: Obliterator cannon has been built!")
  1502.                     elseif sim.partProperty(i, "tmp") == 5 then
  1503.                         print("Gray: Obliterator cannon has been built!")
  1504.                     end
  1505.         end
  1506.     end
  1507. end
  1508.  
  1509. elements.property(builder2, "Update", builder2Update);
  1510.  
  1511. local function builder2Graphics(i, colr, colg, colb)
  1512.     local r;
  1513.     local g;
  1514.     local b;
  1515.     local tmp = tpt.get_property("tmp", i);
  1516.     if tmp == 0 then
  1517.         r = 255;
  1518.         g = 0;
  1519.         b = 0;
  1520.     elseif tmp == 1 then
  1521.         r = 0;
  1522.         g = 255;
  1523.         b = 0;
  1524.     elseif tmp == 2 then
  1525.         r = 0;
  1526.         g = 0;
  1527.         b = 255;
  1528.     elseif tmp == 3 then
  1529.         r = 255;
  1530.         g = 204;
  1531.         b = 0;
  1532.     elseif tmp == 4 then
  1533.         r = 255;
  1534.         g = 255;
  1535.         b = 255;
  1536.     elseif tmp == 5 then
  1537.         r = 153;
  1538.         g = 153;
  1539.         b = 153;
  1540.     end
  1541.     return 1,0x00000001,255,r,g,b,255,255,255,255;
  1542. end
  1543.  
  1544. elements.property(builder2, "Graphics", builder2Graphics);
  1545.  
  1546. --Kamikaze
  1547. kamikaze = elements.allocate("JosephMA", "KMKZ");
  1548. elements.element(kamikaze, elements.element(elements.DEFAULT_PT_PROT));
  1549. elements.property(kamikaze, "HighTemperature", 1273.15);
  1550. elements.property(kamikaze, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  1551. elements.property(kamikaze, "Name", "KMKZ");
  1552. elements.property(kamikaze, "Description", "Spacecraft kamikaze, explodes when near enemy ships.");
  1553. elements.property(kamikaze, "MenuSection", elem.SC_SPECIAL);
  1554.  
  1555. local function kamikazeUpdate(i, x, y, s, n)
  1556.     --tmp is current team
  1557.     local life = tpt.get_property("life", i);
  1558.     if life == 0 then
  1559.         tpt.set_property("life", fighterLife, i);
  1560.         life = fighterLife;
  1561.     end
  1562.     local rand = math.random(1, 150);
  1563.     if rand <= 75 then
  1564.         for r in sim.neighbors(x,y,1,1) do
  1565.             local partType = sim.partProperty(r, "type");
  1566.             if partType == laser and sim.partProperty(r, "tmp") ~= tpt.get_property("tmp", i) then
  1567.                 sim.partKill(r);
  1568.                 tpt.set_property("life", life - 1, i);
  1569.                 life = life - 1;
  1570.                 if life - 1 <= -1 then
  1571.                     sim.partKill(i);
  1572.                     totalshipdest = totalshipdest + 1
  1573.                     return 1;
  1574.                 end
  1575.             elseif partType == explosion or partType == elements.DEFAULT_PT_EMBR then
  1576.                 sim.partKill(i);
  1577.                 totalshipdest = totalshipdest + 1
  1578.                 return 1;
  1579.             end
  1580.         end
  1581.     end
  1582.  
  1583.  
  1584.     --Movement
  1585.     if math.random(1, 100) == 1 then
  1586.         if math.random(1, 2) == 1 then
  1587.             tpt.set_property("vx", math.random(-1, 1), i);
  1588.         else
  1589.             tpt.set_property("vy", math.random(-1, 1), i);
  1590.         end
  1591.     end
  1592.  
  1593.  
  1594.     if rand == 1 then
  1595.         for r in sim.neighbors(x,y,10,10) do
  1596.             local partType = sim.partProperty(r, "type");
  1597.             local tmp = tpt.get_property("tmp", i);
  1598.             if (partType == ship or partType == bomber or partType == city or partType == mothership or partType == destroyer or partType == builder or partType == kamikaze or partType == lab) and sim.partProperty(r, "tmp") ~= tmp then
  1599.                 tpt.set_property("vx", (sim.partProperty(r, "x") - x)^0, i);
  1600.                 tpt.set_property("vy", (sim.partProperty(r, "y") - y)^0, i);
  1601.                 break;
  1602.             end
  1603.         end
  1604.  
  1605.  
  1606.  
  1607.         --Explode
  1608.     for r in sim.neighbors(x,y,3,3) do
  1609.         local partType = sim.partProperty(r, "type");
  1610.         local tmp = tpt.get_property("tmp", i);
  1611.             if (partType == ship or partType == bomber or partType == city or partType == mothership or partType == destroyer or partType == builder or partType == lab) and sim.partProperty(r, "tmp") ~= tmp then
  1612.             tpt.set_property("type","expl",i);
  1613.             tpt.set_property("life","0",i);
  1614.                 break;
  1615.             end
  1616.     end
  1617.     end
  1618.  
  1619. end
  1620.  
  1621. elements.property(kamikaze, "Update", kamikazeUpdate);
  1622.  
  1623. local function kamikazeGraphics(i, colr, colg, colb)
  1624.     local r;
  1625.     local g;
  1626.     local b;
  1627.     local tmp = tpt.get_property("tmp", i);
  1628.     if tmp == 0 then
  1629.         r = 255;
  1630.         g = 0;
  1631.         b = 0;
  1632.     elseif tmp == 1 then
  1633.         r = 0;
  1634.         g = 255;
  1635.         b = 0;
  1636.     elseif tmp == 2 then
  1637.         r = 0;
  1638.         g = 0;
  1639.         b = 255;
  1640.     elseif tmp == 3 then
  1641.         r = 255;
  1642.         g = 204;
  1643.         b = 0;
  1644.     elseif tmp == 4 then
  1645.         r = 255;
  1646.         g = 255;
  1647.         b = 255;
  1648.     elseif tmp == 5 then
  1649.         r = 153;
  1650.         g = 153;
  1651.         b = 153;
  1652.     end
  1653.     return 1,0x00000001,255,r,g,b,255,255,255,255;
  1654. end
  1655.  
  1656. elements.property(kamikaze, "Graphics", kamikazeGraphics);
  1657.  
  1658. --Nuke Missile
  1659. nukeMissile = elements.allocate("JosephMA", "MSLE");
  1660. elements.element(nukeMissile, elements.element(elements.DEFAULT_PT_PROT));
  1661. elements.property(nukeMissile, "Name", "MSLE");
  1662. elements.property(nukeMissile, "Colour", 0x5D5D5C);
  1663. elements.property(nukeMissile, "Description", "Nuke missile, explodes after a set life time!");
  1664. elements.property(nukeMissile, "MenuSection", 15);
  1665.  
  1666. local function nukeMissileUpdate(i, x, y, s, n)
  1667.     sim.partProperty(i, "life", sim.partProperty(i, "life") - 1);
  1668.     if sim.partProperty(i, "life") <= 0 then
  1669.         local part = sim.partCreate(-1, x, y, explosion);
  1670.         sim.partProperty(part, "life", 1);
  1671.         --Explode
  1672.         for r in sim.neighbors(x,y,20,20) do
  1673.             local part = sim.partCreate(-3, sim.partProperty(r, "x"), sim.partProperty(r, "y"), elements.DEFAULT_PT_PLSM);
  1674.             sim.partProperty(part, "life", 300);
  1675.             sim.partKill(r);
  1676.         end
  1677.         sim.partKill(i);
  1678.                 totalexpl = totalexpl + 1
  1679.         return 1;
  1680.     end
  1681.     --Smoke Trail
  1682.     local part = sim.partCreate(-1, x, y, elements.DEFAULT_PT_SMKE);
  1683.     sim.partProperty(part, "life", 20);
  1684. end
  1685.  
  1686. elements.property(nukeMissile, "Update", nukeMissileUpdate);
  1687.  
  1688. --Decrafter
  1689. decrafter = elements.allocate("JosephMA", "DCRF");
  1690. elements.element(decrafter, elements.element(elements.DEFAULT_PT_PROT));
  1691. elements.property(decrafter, "HighTemperature", 1273.15);
  1692. elements.property(decrafter, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  1693. elements.property(decrafter, "Name", "DCRF");
  1694. elements.property(decrafter, "Description", "Spacecraft decrafter, steal or destroy enemy obliterators. Very resistant.");
  1695. elements.property(decrafter, "MenuSection", elem.SC_SPECIAL);
  1696.  
  1697. local function decrafterUpdate(i, x, y, s, n)
  1698.     --tmp is current team
  1699.     local life = tpt.get_property("life", i);
  1700.     if life == 0 then
  1701.         tpt.set_property("life", fighterLife, i);
  1702.         life = fighterLife;
  1703.     end;
  1704.         local stuff = 0;
  1705.         if stuff == 0 then
  1706.                 tpt.set_property("life", 10, i);
  1707.                 stuff = 1
  1708.         end;
  1709.     local rand = math.random(1, 150);
  1710.     if rand <= 75 then
  1711.         for r in sim.neighbors(x,y,1,1) do
  1712.             local partType = sim.partProperty(r, "type");
  1713.             if partType == laser and sim.partProperty(r, "tmp") ~= tpt.get_property("tmp", i) then
  1714.                 sim.partKill(r);
  1715.                 tpt.set_property("life", life - 1, i);
  1716.                 life = life - 1;
  1717.                 if life - 1 <= -1 then
  1718.                     sim.partKill(i);
  1719.                                         totalshipdest = totalshipdest + 1
  1720.                     return 1;
  1721.                 end
  1722.             elseif partType == explosion or partType == elements.DEFAULT_PT_EMBR or partType == elements.DEFAULT_PT_CAUS then
  1723.                 sim.partKill(r);
  1724.                 tpt.set_property("life", life - 1, i);
  1725.                 life = life - 1;
  1726.                 if life - 1 <= -1 then
  1727.                     sim.partKill(i);
  1728.                                         totalshipdest = totalshipdest + 1
  1729.                     return 1;
  1730.                 end
  1731.             end
  1732.         end
  1733.     end
  1734.     --Movement
  1735.     if math.random(1, 100) == 1 then
  1736.         if math.random(1, 2) == 1 then
  1737.             tpt.set_property("vx", math.random(-1, 1), i);
  1738.         else
  1739.             tpt.set_property("vy", math.random(-1, 1), i);
  1740.         end
  1741.     end
  1742.     --Destroy or steal
  1743.         for r in sim.neighbors(x,y,5,5) do
  1744.             local partType = sim.partProperty(r, "type");
  1745.             local tmp = tpt.get_property("tmp", i);
  1746.             local enemytmp = tpt.get_property("tmp", r)
  1747.                 if (partType == obliteratorCannon) and sim.partProperty(r, "tmp") ~= tmp then
  1748.                     random = math.random(1, 5)
  1749.                     if random > 1 then
  1750.                         tpt.set_property("type","msle",i);
  1751.                         tpt.set_property("life","100",i);
  1752.                         tpt.set_property("vx","0",i);
  1753.                         tpt.set_property("vy","0",i);
  1754.                         print(getFraction(tmp, 1) .. ": A decrafter has set a nuke near a " .. getFraction(enemytmp, 0) .. " obliterator cannon!")
  1755.                     else
  1756.                         tpt.set_property("tmp", tmp, r);
  1757.                         sim.partKill(i);
  1758.                         print(getFraction(tmp, 1) .. ": A decrafter stole a " .. getFraction(enemytmp, 0) .. " obliterator cannon!")
  1759.                         totalstolen = totalstolen + 1
  1760.                     end;
  1761.                     break;
  1762.             end
  1763.         end
  1764. end
  1765.  
  1766. elements.property(decrafter, "Update", decrafterUpdate);
  1767.  
  1768. local function decrafterGraphics(i, colr, colg, colb)
  1769.     local r;
  1770.     local g;
  1771.     local b;
  1772.     local tmp = tpt.get_property("tmp", i);
  1773.     if tmp == 0 then
  1774.         r = 255;
  1775.         g = 0;
  1776.         b = 0;
  1777.     elseif tmp == 1 then
  1778.         r = 0;
  1779.         g = 255;
  1780.         b = 0;
  1781.     elseif tmp == 2 then
  1782.         r = 0;
  1783.         g = 0;
  1784.         b = 255;
  1785.     elseif tmp == 3 then
  1786.         r = 255;
  1787.         g = 204;
  1788.         b = 0;
  1789.     elseif tmp == 4 then
  1790.         r = 255;
  1791.         g = 255;
  1792.         b = 255;
  1793.     elseif tmp == 5 then
  1794.         r = 153;
  1795.         g = 153;
  1796.         b = 153;
  1797.     end
  1798.     local x = tpt.get_property("x",i);
  1799.     local y = tpt.get_property("y",i);
  1800.     graphics.fillRect(x - 1, y - 1, 3, 3, r, g, b);
  1801. end
  1802.  
  1803. elements.property(decrafter, "Graphics", decrafterGraphics);
  1804.  
  1805. --Terraformer
  1806. terraformer = elements.allocate("JosephMA", "TFRM");
  1807. elements.element(terraformer, elements.element(elements.DEFAULT_PT_PROT));
  1808. elements.property(terraformer, "HighTemperature", 1273.15);
  1809. elements.property(terraformer, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  1810. elements.property(terraformer, "Name", "TFRM");
  1811. elements.property(terraformer, "Description", "Spacecraft terraformer , makes planets more suitable for life.");
  1812. elements.property(terraformer, "MenuSection", elem.SC_SPECIAL);
  1813.  
  1814. local function terraformerUpdate(i, x, y, s, n)
  1815.     --tmp is current team
  1816.     local life = tpt.get_property("life", i);
  1817.     if life == 0 then
  1818.         tpt.set_property("life", mothershipLife, i);
  1819.         life = mothershipLife;
  1820.     end
  1821.     local rand = math.random(1, 30);
  1822.     if rand <= 15 then
  1823.         for r in sim.neighbors(x,y,1,1) do
  1824.             local partType = sim.partProperty(r, "type");
  1825.             if partType == laser and sim.partProperty(r, "tmp") ~= tpt.get_property("tmp", i) then
  1826.                 sim.partKill(r);
  1827.                 tpt.set_property("life", life - 1, i);
  1828.                 life = life - 1;
  1829.                 if life - 1 <= -1 then
  1830.                     sim.partKill(i);
  1831.                     return 1;
  1832.                 end
  1833.             elseif partType == explosion or partType == elements.DEFAULT_PT_EMBR then
  1834.                 tpt.set_property("life", life - 1, i);
  1835.                 if life - 1 <= -1 then
  1836.                     sim.partKill(i);
  1837.                     return 1;
  1838.                 end
  1839.             end
  1840.         end
  1841.     end
  1842.     --Movement
  1843.     if math.random(1, 100) == 1 then
  1844.         if math.random(1, 2) == 1 then
  1845.             tpt.set_property("vx", math.random(-1, 1), i);
  1846.         else
  1847.             tpt.set_property("vy", math.random(-1, 1), i);
  1848.         end
  1849.     end
  1850.     --Shooting
  1851.     if math.random(1, 50) == 1 then
  1852.         for r in sim.neighbors(x,y,10,10) do
  1853.             local partType = sim.partProperty(r, "type");
  1854.             local partcType = sim.partProperty(r, "ctype");
  1855.             local tmp = tpt.get_property("tmp", i);
  1856.             if partType == rock and sim.partProperty(r, "temp") < 400 then
  1857.                 sim.partChangeType(r, continent);
  1858.                 sim.partProperty(r, "tmp", tmp);
  1859.                 sim.partProperty(r, "tmp2", 1);
  1860.             end
  1861.             if partType == desert and sim.partProperty(r, "temp") < 400 then
  1862.                 sim.partChangeType(r, ocean);
  1863.             end
  1864.             if partType == rock or partType == desert or partcType == rock or partcType == desert and sim.partProperty(r, "temp") > 400 and sim.partProperty(r, "temp") < 3273 then
  1865.             sim.partProperty(r, "temp", sim.partProperty(r, "temp")-500);
  1866.             end
  1867.         end
  1868.     end
  1869. end
  1870.  
  1871. elements.property(terraformer, "Update", terraformerUpdate);
  1872.  
  1873. local function terraformerGraphics(i, colr, colg, colb)
  1874.     local r;
  1875.     local g;
  1876.     local b;
  1877.     local tmp = tpt.get_property("tmp", i);
  1878.     if tmp == 0 then
  1879.         r = 255;
  1880.         g = 0;
  1881.         b = 0;
  1882.     elseif tmp == 1 then
  1883.         r = 0;
  1884.         g = 255;
  1885.         b = 0;
  1886.     elseif tmp == 2 then
  1887.         r = 0;
  1888.         g = 0;
  1889.         b = 255;
  1890.     elseif tmp == 3 then
  1891.         r = 255;
  1892.         g = 204;
  1893.         b = 0;
  1894.     elseif tmp == 4 then
  1895.         r = 255;
  1896.         g = 255;
  1897.         b = 255;
  1898.     elseif tmp == 5 then
  1899.         r = 153;
  1900.         g = 153;
  1901.         b = 153;
  1902.     end
  1903. --    local x = tpt.get_property("x",i);
  1904. --    local y = tpt.get_property("y",i);
  1905. --    graphics.fillRect(x - 4, y - 4, 9, 9, r, g, b);
  1906. end
  1907.  
  1908. elements.property(terraformer, "Graphics", terraformerGraphics);
  1909.  
  1910. --Obliterator cannon
  1911. obliteratorCannon = elements.allocate("JosephMA", "OBLC");
  1912. elements.element(obliteratorCannon, elements.element(elements.DEFAULT_PT_BRCK));
  1913. elements.property(obliteratorCannon, "HighTemperature", 873.15);
  1914. elements.property(obliteratorCannon, "HighTemperatureTransition", elements.DEFAULT_PT_BRMT);
  1915. elements.property(obliteratorCannon, "Name", "OBLC");
  1916. elements.property(obliteratorCannon, "Description", "Obliterator cannon destroys the universe.");
  1917. elements.property(obliteratorCannon, "MenuSection", elem.SC_SPECIAL);
  1918.  
  1919. local function obliteratorCannonUpdate(i, x, y, s, n)
  1920.     if math.random(1, 500) == 1 then
  1921.         for r in sim.neighbors(x,y,100,100) do
  1922.             local partType = sim.partProperty(r, "type");
  1923.             local tmp = tpt.get_property("tmp", i);
  1924.             if (partType == ship or partType == bomber or partType == city or partType == mothership or partType == destroyer or partType == builder or partType == ship2 or partType == bomber2 or partType == lab) and sim.partProperty(r, "tmp") ~= tmp then
  1925.                 if partType ~= city then
  1926.                     --Nuke missile
  1927.                     local part = sim.partCreate(-3, x, y, nukeMissile);
  1928.                     tpt.set_property("vx", sim.partProperty(r, "x") - x, part);
  1929.                     tpt.set_property("vy", sim.partProperty(r, "y") - y, part);
  1930.                     --tpt.set_property("tmp", tmp, part);
  1931.                     tpt.set_property("life", 65, part);
  1932.                 else
  1933.                     --Destroy
  1934.                     if math.random(1, 50) <= 49 then
  1935.                         sim.partChangeType(r, rock);
  1936.                     else
  1937.                         sim.partChangeType(r, elements.DEFAULT_PT_BOMB);
  1938.                     end
  1939.                 end
  1940.             end
  1941.         end
  1942.         --Fire missiles
  1943.         for t=0, 50, 1
  1944.         do
  1945.             local part = sim.partCreate(-3, x, y, missile);
  1946.             tpt.set_property("life", math.random() * 150, part);
  1947.             local angle = math.random() * 2.0 * math.pi/0.5;
  1948.             local v = (math.random()) * 5.0/0.5;
  1949.             tpt.set_property("vx", v * math.cos(angle), part);
  1950.             tpt.set_property("vy", v * math.sin(angle), part);
  1951.         end
  1952.     end
  1953. end
  1954.  
  1955. elements.property(obliteratorCannon, "Update", obliteratorCannonUpdate);
  1956.  
  1957. local function obliteratorCannonGraphics(i, colr, colg, colb)
  1958.     local r;
  1959.     local g;
  1960.     local b;
  1961.     local tmp = tpt.get_property("tmp", i);
  1962.     if tmp == 0 then
  1963.         r = 255;
  1964.         g = 0;
  1965.         b = 0;
  1966.     elseif tmp == 1 then
  1967.         r = 0;
  1968.         g = 255;
  1969.         b = 0;
  1970.     elseif tmp == 2 then
  1971.         r = 0;
  1972.         g = 0;
  1973.         b = 255;
  1974.     elseif tmp == 3 then
  1975.         r = 255;
  1976.         g = 204;
  1977.         b = 0;
  1978.     elseif tmp == 4 then
  1979.         r = 255;
  1980.         g = 255;
  1981.         b = 255;
  1982.     elseif tmp == 5 then
  1983.         r = 153;
  1984.         g = 153;
  1985.         b = 153;
  1986.     end
  1987.     tpt.drawline(sim.partProperty(i, "x"), sim.partProperty(i, "y"), sim.partProperty(i, "x") + 5, sim.partProperty(i, "y"), r, g, b)
  1988.     return 1,0x00000001,255,r,g,b,255,255,255,255;
  1989. end
  1990.  
  1991. elements.property(obliteratorCannon, "Graphics", obliteratorCannonGraphics);
  1992.  
  1993. local function rockUpdate(i, x, y, s, n)
  1994.     local life = sim.partProperty(i, "life");
  1995.     if life > 0 then
  1996.         sim.partProperty(i, "life", life - 1);
  1997.         for r in sim.neighbors(x,y,1,1) do
  1998.             if math.random(1, 8) == 1 and sim.partProperty(r, "type") == desert then
  1999.                 sim.partChangeType(r, rock);
  2000.                 sim.partProperty(r, "life", life - 1);
  2001.             end
  2002.         end
  2003.     end
  2004. end
  2005. elements.property(rock, "Update", rockUpdate);
  2006.  
  2007. local function planetUpdate(i, x, y, s, n)
  2008.     if sim.partProperty(i, "tmp") == 0 then
  2009.         if math.random(1, 20) == 1 then
  2010.             sim.partProperty(i, "life", math.random(0, 10));
  2011.             sim.partChangeType(i, continent);
  2012.         else
  2013.             sim.partChangeType(i, ocean);
  2014.         end
  2015.     end;
  2016.     if sim.partProperty(i, "tmp") == 1 then
  2017.         if math.random(1, 20) == 1 then
  2018.             sim.partProperty(i, "life", math.random(0, 10));
  2019.             sim.partChangeType(i, rock);
  2020.         else
  2021.             sim.partChangeType(i, desert);
  2022.         end
  2023.     end
  2024. end;
  2025. elements.property(planet, "Update", planetUpdate);
  2026. local function dplanetUpdate(i, x, y, s, n)
  2027.     sim.partProperty(i, "tmp", 1);
  2028.     sim.partChangeType(i, planet)
  2029. end;
  2030. elements.property(dplanet, "Update", dplanetUpdate);
  2031.  
  2032. lab = elements.allocate("JosephMA", "LAB");
  2033. elements.element(lab, elements.element(elements.DEFAULT_PT_BRCK));
  2034. elements.property(lab, "Name", "LAB");
  2035. elements.property(lab, "Colour", 0x00FFDE);
  2036. elements.property(lab, "Description", "Laboratory expands technologies");
  2037. elements.property(lab, "MenuSection", 15);
  2038.  
  2039. local function labUpdate(i, x, y, s, n)
  2040.     if sim.partProperty(i, "tmp2") == 1 then
  2041.         if sim.partProperty(i, "tmp") == 0 then
  2042.             rTech = rTech + 1
  2043.         elseif sim.partProperty(i, "tmp") == 1 then
  2044.             gTech = gTech + 1
  2045.         elseif sim.partProperty(i, "tmp") == 2 then
  2046.             bTech = bTech + 1
  2047.         elseif sim.partProperty(i, "tmp") == 3 then
  2048.             gdTech = gdTech + 1
  2049.         elseif sim.partProperty(i, "tmp") == 4 then
  2050.             wTech = wTech + 1
  2051.         elseif sim.partProperty(i, "tmp") == 5 then
  2052.             gyTech = gyTech + 1
  2053.         end;
  2054.         sim.partProperty(i, "tmp2", 2)
  2055.     end
  2056. end
  2057. elements.property(lab, "Update", labUpdate);
  2058. local function showLabs(key, nkey, modifier, event)
  2059.     if key == "m" and event == 2 then
  2060.         print("Red lab research: " .. rTech*5 .. "%");
  2061.         print("Green lab research: " .. gTech*5 .. "%");
  2062.         print("Blue lab reserach: " .. bTech*5 .. "%");
  2063.         print("Golden lab research: " .. gdTech*5 .. "%");
  2064.         print("White lab research: " .. wTech*5 .. "%");
  2065.         print("Gray lab research: " .. gyTech*5 .. "%");
  2066.         if obliterators == 0 then
  2067.             print("Obliterator cannons: Not yet deployed")
  2068.         else
  2069.             print("Obliterator cannons: Deployed!")
  2070.         end;
  2071.         if splits == 0 then
  2072.             print("Split ships: Not yet invented.")
  2073.         else
  2074.             print("Split ships: Deployed! (first by the " .. getFraction(splitcreator, 0) .. " scientists)")
  2075.         end
  2076.     end
  2077. end;
  2078. tpt.register_keypress(showLabs)
  2079. local function totals(key, nkey, modifier, event)
  2080.     if key == "t" and event == 2 then
  2081.         print("Statistics:")
  2082.         print("Total labs built: " .. totallabs)
  2083.         print("Total destroyers constructed: " .. totaldest)
  2084.         print("Total obliterators stolen: " .. totalstolen)
  2085.         print("Total missiles exploded: " .. totalexpl)
  2086.         print("Total ships destroyed (by their enemies): " .. totalshipdest)
  2087.     end
  2088. end
  2089. tpt.register_keypress(totals)
  2090. local function reset(mousex, mousey, button, event)
  2091.     tpt.drawrect(613, 113, 14, 14, 204, 204, 204)
  2092.     tpt.fillrect(613, 113, 14, 14, 0, 0, 0, 255)
  2093.     tpt.drawtext(618, 117, "R", 255, 255, 255, 255)
  2094.     if tpt.mousex >= 613 and tpt.mousey >= 113 and tpt.mousex <= 627 and tpt.mousey <= 127 then
  2095.         tpt.drawtext(537, 115, "Reset progress", 255, 0, 0, 255)
  2096.         tpt.drawrect(613, 113, 14, 14, 255, 255, 255)
  2097.     end
  2098.     if tpt.mousex >= 613 and tpt.mousey >= 113 and tpt.mousex <= 627 and tpt.mousey <= 127 then
  2099.         if event == 1 then
  2100.             rTech = 0;
  2101.             gTech = 0
  2102.             bTech = 0;
  2103.             gdTech = 0;
  2104.             wTech = 0;
  2105.             gyTech = 0;
  2106.             obliterators = 0;
  2107.             splits = 0;
  2108.             splitcreator = nil;
  2109.             totallabs = 0;
  2110.             totaldest = 0;
  2111.             totalstolen = 0;
  2112.             totalexpl = 0;
  2113.             totalshipdest = 0;
  2114.         end
  2115.     end
  2116. end
  2117. tpt.register_mouseclick(reset)
  2118. tpt.register_step(reset)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement