Concrete now wets from 1 to 4, added freezing damage

This commit is contained in:
Laetitia (O-01-67) 2023-03-08 14:36:34 -05:00 committed by GitHub
parent 0513aade3a
commit 08e4e3f1bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 79 additions and 19 deletions

View File

@ -2413,8 +2413,8 @@ if(!enabledMods.includes(libraryMod)) {
elements.concrete.properties.composition = "mafic"; elements.concrete.properties.composition = "mafic";
elements.concrete.tick = function(pixel) { elements.concrete.tick = function(pixel) {
pixel.composition ??= "mafic"; pixel.composition ??= "mafic";
pixel.wet ??= (Math.random() < 0.03); pixel.wet ??= Math.random() < 0.03 ? 1 : 0;
pixel.didWetColorChange ??= false; pixel.frozen ??= false;
pixel.didColorChange ??= 0; pixel.didColorChange ??= 0;
pixel.lastTemperatures ??= []; pixel.lastTemperatures ??= [];
@ -2429,10 +2429,27 @@ if(!enabledMods.includes(libraryMod)) {
var magmaName = (pixel.composition == "mafic") ? "magma" : pixel.composition + "_magma"; var magmaName = (pixel.composition == "mafic") ? "magma" : pixel.composition + "_magma";
var magmaTempHigh = Math.max(...Object.values(elements[magmaName]._magmaCoolingPassToElement.meltingPoints)); var magmaTempHigh = Math.max(...Object.values(elements[magmaName]._magmaCoolingPassToElement.meltingPoints));
if(pixel.wet && !pixel.didWetColorChange) { if(pixel.wet && !pixel.frozen && pixel.temp < 0) {
var colorWasHSL = pixel.color.startsWith("hsl"); if(Math.random() < (pixel.wet / 40)) { //if unfrozen, crack apart (freezing damage) with small chance, and then mark survivors as frozen
pixel.color = changeLuminance(pixel.color,11,"-",colorWasHSL ? "hsl" : "rgb"); explodeAt(pixel.x,pixel.y,2,"ice");
pixel.didWetColorChange = true; if(!pixel) { //if deleted
return;
};
if(pixel.element !== "ice") { //chance to just change to ice after the fact if survivor
if(Math.random() < (pixel.wet / 8)) {
changePixel(pixel,"ice",false);
};
};
if(pixel.element !== "concrete") { //if changed, stop execution
return;
};
};
//if unchanged and undeleted, mark as frozen
pixel.frozen = true;
};
if(pixel.frozen && pixel.temp > 0) {
pixel.frozen = false;
}; };
//console.log(pixel.temp,pixel.didColorChange); //console.log(pixel.temp,pixel.didColorChange);
@ -2492,11 +2509,13 @@ if(!enabledMods.includes(libraryMod)) {
if(pixel.wet && pixel.temp > 300) { if(pixel.wet && pixel.temp > 300) {
if(overallTemperatureChangeRate > 25) { //if temp change is fast enough, always spall if(overallTemperatureChangeRate > 25) { //if temp change is fast enough, always spall
explodeAt(pixel.x,pixel.y,Math.random() < 1/3 ? 2 : 1,"steam,dust") if(Math.random() < Math.max(0.25,1.05 - (pixel.wet/20))) { //decresingly less likely to spall as it gets wetter, for balance
if(!pixel || pixel.element !== "concrete") { //if destroyed or changed explodeAt(pixel.x,pixel.y,Math.random() < 1/3 ? 2 : 1,"steam,dust")
return; if(!pixel || pixel.element !== "concrete") { //if destroyed or changed
return;
};
}; };
pixel.wet = false; pixel.wet--;
} else { //if exposed, continuously try to boil off to random neighbor } else { //if exposed, continuously try to boil off to random neighbor
if(exposedToAir(pixel)) { if(exposedToAir(pixel)) {
var randomNeighbor = adjacentCoords[Math.floor(Math.random() * neighbors.length)] var randomNeighbor = adjacentCoords[Math.floor(Math.random() * neighbors.length)]
@ -2504,7 +2523,7 @@ if(!enabledMods.includes(libraryMod)) {
var rny = randomNeighbor[1] var rny = randomNeighbor[1]
if(isEmpty(pixel.x+rnx, pixel.y+rny, false)) { if(isEmpty(pixel.x+rnx, pixel.y+rny, false)) {
createPixel("steam", pixel.x+rnx, pixel.y+rny) createPixel("steam", pixel.x+rnx, pixel.y+rny)
pixel.wet = false; pixel.wet--;
}; };
} else { //if surrounded, lower chance to spall and higher chance to dissipate } else { //if surrounded, lower chance to spall and higher chance to dissipate
if(Math.random() < 0.03) { if(Math.random() < 0.03) {
@ -2514,27 +2533,68 @@ if(!enabledMods.includes(libraryMod)) {
return; return;
}; };
}; };
pixel.wet = false; pixel.wet--;
}; };
}; };
}; };
return; return;
}; };
if(!pixel.wet) { if(Math.random() < 1/3) { //tick wetness behavior only 1/3 of the time, for performance
for(i = 0; i < adjacentCoords.length; i++) { var randomCoords = JSON.parse(JSON.stringify(adjacentCoords)); //so we don't need both an adjacentCoords for *and* a random coord iterator
shuffleArray(randomCoords);
for(i = 0; i < randomCoords.length; i++) {
var coords = [ var coords = [
pixel.x+adjacentCoords[i][0], pixel.x+randomCoords[i][0],
pixel.y+adjacentCoords[i][1] pixel.y+randomCoords[i][1]
]; ];
if(isEmpty(coords[0],coords[1],true)) { if(isEmpty(coords[0],coords[1],true)) {
continue; continue;
} else { } else {
var newPixel = pixelMap[coords[0]]?.[coords[1]]; var newPixel = pixelMap[coords[0]]?.[coords[1]];
if(newPixel?.element) { if(newPixel?.element) {
if(newPixel.element == "water") { if(newPixel.element === "water" && pixel.wet < 4) {
pixel.wet = true; //console.log("touching water",pixel.wet);
if(Math.random() < 1/4) { deletePixel(newPixel.x,newPixel.y) }; if(pixel.wet < 1) {
var colorWasHSL = pixel.color.startsWith("hsl");
pixel.color = changeLuminance(pixel.color,6,"-",colorWasHSL ? "hsl" : "rgb");
pixel.wet = 1;
if(Math.random() < 0.8) { deletePixel(newPixel.x,newPixel.y) };
break;
};
if(pixel.wet == 1) {
var colorWasHSL = pixel.color.startsWith("hsl");
pixel.color = changeLuminance(pixel.color,6,"-",colorWasHSL ? "hsl" : "rgb");
pixel.wet = 2;
if(Math.random() < 0.6) { deletePixel(newPixel.x,newPixel.y) };
break;
};
if(pixel.wet == 2) {
var colorWasHSL = pixel.color.startsWith("hsl");
pixel.color = changeLuminance(pixel.color,6,"-",colorWasHSL ? "hsl" : "rgb");
pixel.wet = 3;
if(Math.random() < 0.4) { deletePixel(newPixel.x,newPixel.y) };
break;
};
if(pixel.wet == 3) {
var colorWasHSL = pixel.color.startsWith("hsl");
pixel.color = changeLuminance(pixel.color,6,"-",colorWasHSL ? "hsl" : "rgb");
pixel.wet = 4;
if(Math.random() < 0.2) { deletePixel(newPixel.x,newPixel.y) };
break;
};
} else {
//console.log(3);
if(pixel.wet > 1 && !pixel.frozen && newPixel.element.endsWith("concrete") && newPixel.wet != undefined && newPixel.wet < pixel.wet) {
if(pixel.wet <= 1) { break };
pixel.wet--;
var colorWasHSL = pixel.color.startsWith("hsl");
pixel.color = changeLuminance(pixel.color,6,"+",colorWasHSL ? "hsl" : "rgb");
newPixel.wet++;
var newColorWasHSL = newPixel.color.startsWith("hsl");
newPixel.color = changeLuminance(newPixel.color,6,"-",newColorWasHSL ? "hsl" : "rgb");
};
}; };
}; };
}; };