diff --git a/mods/fire_mod.js b/mods/fire_mod.js index 28471b3b..301ef1bd 100644 --- a/mods/fire_mod.js +++ b/mods/fire_mod.js @@ -1,666 +1,584 @@ -/* elements.iron.reactions.radiation = - {elem1: 'dirty_water', elem2: null} - when radiation touches iron, - the iron turns into dirty_water (elem1) - and the radiation deletes itself (elem2) +var modName = "mods/random_rocks.js"; +var libraryMod = "mods/code_library.js"; - elements.AAA.reactions.BBB: - {elem1: CCC, elem2: DDD} - when BBB touches AAA, - the AAA becomes CCC - and the BBB becomes DDD -*/ +if(enabledMods.includes(libraryMod)) { + /* elements.iron.reactions.radiation = + {elem1: 'dirty_water', elem2: null} + when radiation touches iron, + the iron turns into dirty_water (elem1) + and the radiation deletes itself (elem2) -// imaginary reaction elements.iron.reactions.test + elements.AAA.reactions.BBB: + {elem1: CCC, elem2: DDD} + when BBB touches AAA, + the AAA becomes CCC + and the BBB becomes DDD + */ -//Variable -fireSpawnBlacklist = ["fire","cold_fire","rad_fire"]; + // imaginary reaction elements.iron.reactions.test -//doBurning -function doBurning(pixel) { - if (pixel.burning) { // Burning - var info = elements[pixel.element]; - var burnTempChange = info.burnTempChange - if (burnTempChange == undefined) { - burnTempChange = 1; - }; - //move fire ahead so that cold burners don't light hot burners - var fireIsCold; - //Fire getter block - var fire = info.fireElement; - if (fire == undefined) { - fire = 'fire'; - } - else if(fire instanceof Array) { - fire = fire[Math.floor(Math.random()*fire.length)]; - } - //End fire getter block - //Fire temp getter block - var fireTemp = info.fireSpawnTemp; - if (fireTemp == undefined) { - fireTemp = pixel.temp; + //Variable + fireSpawnBlacklist = ["fire","cold_fire","rad_fire"]; + + //doBurning + function doBurning(pixel) { + if (pixel.burning) { // Burning + var info = elements[pixel.element]; + var burnTempChange = info.burnTempChange + if (burnTempChange == undefined) { + burnTempChange = 1; }; - //End fire temp getter block - //Fire chance getter block - var fireChance = info.fireSpawnChance; - if (fireChance == undefined) { - fireChance = 10; - }; - //End fire chance getter block - var fireIsCold = (fire === "cold_fire"); - var fireInfo = elements[fire]; + //move fire ahead so that cold burners don't light hot burners + var fireIsCold; + //Fire getter block + var fire = info.fireElement; + if (fire == undefined) { + fire = 'fire'; + } + else if(fire instanceof Array) { + fire = fire[Math.floor(Math.random()*fire.length)]; + } + //End fire getter block + //Fire temp getter block + var fireTemp = info.fireSpawnTemp; + if (fireTemp == undefined) { + fireTemp = pixel.temp; + }; + //End fire temp getter block + //Fire chance getter block + var fireChance = info.fireSpawnChance; + if (fireChance == undefined) { + fireChance = 10; + }; + //End fire chance getter block + var fireIsCold = (fire === "cold_fire"); + var fireInfo = elements[fire]; - pixel.temp += burnTempChange; - pixelTempCheck(pixel); - - for (var i = 0; i < adjacentCoords.length; i++) { // Burn adjacent pixels - var x = pixel.x+adjacentCoords[i][0]; - var y = pixel.y+adjacentCoords[i][1]; - if (!isEmpty(x,y,true)) { - var newPixel = pixelMap[x][y]; - var newInfo = elements[newPixel.element]; - var newFireIsCold; - //Fire getter block - var newFire = newInfo.fireElement; - if (newFire == undefined) { - newFire = 'fire'; - } - else if(newFire instanceof Array) { - newFire = newFire[Math.floor(Math.random()*newFire.length)]; - } - //End fire getter block - newFireIsCold = (newFire === "cold_fire"); + pixel.temp += burnTempChange; + pixelTempCheck(pixel); + + for (var i = 0; i < adjacentCoords.length; i++) { // Burn adjacent pixels + var x = pixel.x+adjacentCoords[i][0]; + var y = pixel.y+adjacentCoords[i][1]; + if (!isEmpty(x,y,true)) { + var newPixel = pixelMap[x][y]; + var newInfo = elements[newPixel.element]; + var newFireIsCold; + //Fire getter block + var newFire = newInfo.fireElement; + if (newFire == undefined) { + newFire = 'fire'; + } + else if(newFire instanceof Array) { + newFire = newFire[Math.floor(Math.random()*newFire.length)]; + } + //End fire getter block + newFireIsCold = (newFire === "cold_fire"); - //console.log(`burning pixel ${pixel.element}: ${fire} (${fireIsCold}) / burned element ${newPixel.element}: ${newFire} (${newFireIsCold})`); - if((!fireIsCold && !newFireIsCold) || (fireIsCold && newFireIsCold)) { - if (elements[newPixel.element].burn && !newPixel.burning) { - if (Math.floor(Math.random()*100) < elements[newPixel.element].burn) { - newPixel.burning = true; - newPixel.burnStart = pixelTicks; + //console.log(`burning pixel ${pixel.element}: ${fire} (${fireIsCold}) / burned element ${newPixel.element}: ${newFire} (${newFireIsCold})`); + if((!fireIsCold && !newFireIsCold) || (fireIsCold && newFireIsCold)) { + if (elements[newPixel.element].burn && !newPixel.burning) { + if (Math.floor(Math.random()*100) < elements[newPixel.element].burn) { + newPixel.burning = true; + newPixel.burnStart = pixelTicks; + } } } } } - } - if ((pixelTicks - pixel.burnStart > (info.burnTime || 200)) && Math.floor(Math.random()*100)<(info.burn || 10)) { - var burnInto = info.burnInto; - if (burnInto == undefined) { - burnInto = 'fire'; + if ((pixelTicks - pixel.burnStart > (info.burnTime || 200)) && Math.floor(Math.random()*100)<(info.burn || 10)) { + var burnInto = info.burnInto; + if (burnInto == undefined) { + burnInto = 'fire'; + } + else if (burnInto instanceof Array) { + burnInto = burnInto[Math.floor(Math.random()*burnInto.length)]; + } + changePixel(pixel,burnInto,(burnInto !== "smoke")); + if (info.fireColor != undefined && burnInto == "fire") { + pixel.color = pixelColorPick(pixel,info.fireColor); + } + else { + pixel.color = pixelColorPick(pixel) + } } - else if (burnInto instanceof Array) { - burnInto = burnInto[Math.floor(Math.random()*burnInto.length)]; - } - changePixel(pixel,burnInto,(burnInto !== "smoke")); - if (info.fireColor != undefined && burnInto == "fire") { - pixel.color = pixelColorPick(pixel,info.fireColor); - } - else { - pixel.color = pixelColorPick(pixel) - } - } - else if (Math.floor(Math.random()*100) r.tempMax) { - return false; - } - if (r.charged && !pixel.charge) { - return false; - } - if (r.chance !== undefined && Math.random() > r.chance) { - return false; - } - if (r.y !== undefined && (pixel1.y < r.y[0] || pixel1.y > r.y[1])) { - return false; - } - if (r.elem1 !== undefined) { - // if r.elem1 is an array, set elem1 to a random element from the array, otherwise set it to r.elem1 - if (Array.isArray(r.elem1)) { - var elem1 = r.elem1[Math.floor(Math.random() * r.elem1.length)]; - } else { var elem1 = r.elem1; } - - if (elem1 == null) { - deletePixel(pixel1.x,pixel1.y); - } - else { - changePixel(pixel1,elem1); - } - } - if (r.charge1) { pixel1.charge = r.charge1; } - if (r.temp1) { pixel1.temp += r.temp1; pixelTempCheck(pixel1); } - if (r.color1) { // if it's a list, use a random color from the list, else use the color1 attribute - pixel1.color = pixelColorPick(pixel1, Array.isArray(r.color1) ? r.color1[Math.floor(Math.random() * r.color1.length)] : r.color1); - } - if (r.attr1) { // add each attribute to pixel1 - for (var key in r.attr1) { - pixel1[key] = r.attr1[key]; - } - } - if (r.elem2 !== undefined) { - // if r.elem2 is an array, set elem2 to a random element from the array, otherwise set it to r.elem2 - if (Array.isArray(r.elem2)) { - var elem2 = r.elem2[Math.floor(Math.random() * r.elem2.length)]; - } else { var elem2 = r.elem2; } - - if (elem2 == null) { - deletePixel(pixel2.x,pixel2.y); - } - else { - changePixel(pixel2,elem2); - } - } - if (r.charge2) { pixel2.charge = r.charge2; } - if (r.temp2) { pixel2.temp += r.temp2; pixelTempCheck(pixel2); } - if (r.color2) { // if it's a list, use a random color from the list, else use the color2 attribute - pixel2.color = pixelColorPick(pixel2, Array.isArray(r.color2) ? r.color2[Math.floor(Math.random() * r.color2.length)] : r.color2); - } - if (r.attr2) { // add each attribute to pixel2 - for (var key in r.attr2) { - pixel2[key] = r.attr2[key]; - } - } - if (r.func) { r.func(pixel1,pixel2); } - return r.elem1!==undefined || r.elem2!==undefined; -}; - -//New elements - -elements.cold_fire.burning = true; -elements.cold_fire.burnTempChange = -1; -elements.cold_fire.burnTime = 25; -elements.cold_fire.burnInto = "cold_smoke"; -elements.cold_fire.fireElement = "cold_fire"; -elements.cold_fire.behavior = [ - "M1|M1|M1", - "M2|XX|M2", - "XX|M2|XX" -], - -elements.cold_smoke = { - color: "#282848", - behavior: behaviors.DGAS, - reactions: { - "steam": { "elem1": "pyrocumulus", "chance":0.08, "y":[0,12], "setting":"clouds" }, - "rain_cloud": { "elem1": "pyrocumulus", "chance":0.08, "y":[0,12], "setting":"clouds" }, - "cloud": { "elem1": "pyrocumulus", "chance":0.08, "y":[0,12], "setting":"clouds" }, - "snow_cloud": { "elem1": "pyrocumulus", "chance":0.08, "y":[0,12], "setting":"clouds" }, - "hail_cloud": { "elem1": "pyrocumulus", "chance":0.08, "y":[0,12], "setting":"clouds" }, - "acid_cloud": { "elem1": "pyrocumulus", "chance":0.05, "y":[0,12], "setting":"clouds" }, - "fire_cloud": { "elem1": "pyrocumulus", "chance":0.05, "y":[0,12], "setting":"clouds" }, - "pyrocumulus": { "elem1": "pyrocumulus", "chance":0.08, "y":[0,12], "setting":"clouds" }, - }, - temp: -100, - tempHigh: 0, - stateHigh: "smoke", - tempLow: -114, - stateLow: "cold_fire", - category: "gases", - state: "gas", - density: 1280, - stain: 0.075, -}; - -elements.rad_fire = { //this is BBB - color: ["#daff21","#a6ff00","#ffff00"], - behavior: [ - "XX|CR:radiation%0.1|XX", - "CR:radiation%0.1|XX|CR:radiation%0.1", - "XX|CR:radiation%0.1|XX", - ], - tick: function(pixel) { - if(Math.random() < 0.4) { - pixel.temp++; - }; - - if(Math.random() < 0.05) { //5%/t to radify - if(typeof(transformAdjacent) === "function" && typeof(radioactiveObject) === "object") { - transformAdjacent(pixel,radioactiveObject); - }; - }; - - var move1Spots = [[-1,-1],[0,-1],[1,-1]]; - var move2Spots = [[-1,0],[0,1],[1,0]]; - - var randomMove1 = move1Spots[Math.floor(Math.random() * move1Spots.length)]; - - if(!tryMove(pixel, pixel.x+randomMove1[0], pixel.y+randomMove1[1])) { - //console.log((pixel.x+randomMove1[0]) + " " + (pixel.y+randomMove1[1])) - var newPixel = null; - if(!outOfBounds(pixel.x+randomMove1[0],pixel.y+randomMove1[1])) { - newPixel = pixelMap[pixel.x+randomMove1[0]][pixel.y+randomMove1[1]]; //newPixel is AAA - }; - if(outOfBounds(pixel.x+randomMove1[0],pixel.y+randomMove1[1]) || !reactionStealer(pixel,newPixel,"radiation")) { - var randomMove2 = move2Spots[Math.floor(Math.random() * move2Spots.length)]; - if(!tryMove(pixel, pixel.x+randomMove2[0], pixel.y+randomMove2[1])) { - var newPixel = null; - if(!outOfBounds(pixel.x+randomMove1[0],pixel.y+randomMove1[1])) { - newPixel = pixelMap[pixel.x+randomMove1[0]][pixel.y+randomMove1[1]]; //newPixel is AAA + else if (Math.floor(Math.random()*100)