sandboxels/mods/single_humans.js

148 lines
6.1 KiB
JavaScript
Raw Permalink Normal View History

2024-10-16 22:56:47 -04:00
elements.single_human = {
color: ["#f3e7db","#f7ead0","#eadaba","#d7bd96","#a07e56","#825c43","#604134","#3a312a"],
category: "life",
tick: function(pixel) {
if (tryMove(pixel, pixel.x, pixel.y+1)) {} // Fall
doHeat(pixel);
doBurning(pixel);
doElectricity(pixel);
if (pixel.dead) {
// Turn into rotten_meat if pixelTicks-dead > 500
if (pixelTicks-pixel.dead > 200 && Math.random() < 0.1) {
changePixel(pixel,"rotten_meat");
}
return
}
if (pixel.panic > 0) {
pixel.panic -= 0.1;
if (pixel.panic < 0) { pixel.panic = 0; }
}
if (Math.random() < 0.1*(isEmpty(pixel.x, pixel.y+1) ? 1 : pixel.panic+1)) { // Move 10% chance
var movesToTry = [
[1*pixel.dir,0],
[1*pixel.dir,-1],
];
// While movesToTry is not empty, tryMove(pixel, x, y) with a random move, then remove it. if tryMove returns true, break.
while (movesToTry.length > 0) {
var move = movesToTry.splice(Math.floor(Math.random() * movesToTry.length), 1)[0];
if (isEmpty(pixel.x+move[0], pixel.y+move[1]-1)) {
var origx = pixel.x+move[0];
var origy = pixel.y+move[1];
if (tryMove(pixel, pixel.x+move[0], pixel.y+move[1]) && pixel.x===origx && pixel.y===origy) {
break;
}
}
else if (!isEmpty(pixel.x+move[0], pixel.y+move[1], true)) {
var hitPixel = pixelMap[pixel.x+move[0]][pixel.y+move[1]];
if (hitPixel.element === "single_human") {
// interact with other humans
hitPixel.panic = pixel.panic;
}
}
}
// 15% chance to change direction
if (Math.random() < 0.15) {
pixel.dir *= -1;
}
// homeostasis
if (pixel.temp > 37) { pixel.temp -= 1; }
else if (pixel.temp < 37) { pixel.temp += 1; }
}
},
hidden: true,
density: 1080,
state: "solid",
conduct: .05,
temp: 37,
tempHigh: 200,
stateHigh: "cooked_meat",
tempLow: -30,
stateLow: "frozen_meat",
burn: 10,
burnTime: 250,
burnInto: "cooked_meat",
breakInto: ["blood","meat","bone"],
forceSaveColor: true,
reactions: {
"cancer": { elem1:"cancer", chance:0.005 },
"radiation": { elem1:["ash","meat","rotten_meat","cooked_meat"], chance:0.4 },
"neutron": { elem1:["ash","meat","rotten_meat","cooked_meat"], chance:0.03 },
"fallout": { elem1:["ash","meat","rotten_meat","cooked_meat"], chance:0.03 },
"plague": { elem1:"plague", chance:0.05 },
"oxygen": { elem2:"carbon_dioxide", chance:0.5 },
"meat": { elem2:null, chance:0.1 },
"cooked_meat": { elem2:null, chance:0.1 },
"cured_meat": { elem2:null, chance:0.1 },
"sugar": { elem2:null, chance:0.1 },
"broth": { elem2:null, chance:0.2 },
"yolk": { elem2:null, chance:0.1 },
"hard_yolk": { elem2:null, chance:0.1 },
"dough": { elem2:null, chance:0.1 },
"batter": { elem2:null, chance:0.2 },
"butter": { elem2:null, chance:0.1 },
"melted_butter": { elem2:null, chance:0.2 },
"chocolate": { elem2:null, chance:0.2 },
"melted_chocolate": { elem2:null, chance:0.3 },
"grape": { elem2:null, chance:0.1 },
"tomato": { elem2:null, chance:0.1 },
"herb": { elem2:null, chance:0.1 },
"lettuce": { elem2:null, chance:0.1 },
"corn": { elem2:null, chance:0.1 },
"popcorn": { elem2:null, chance:0.15 },
"potato": { elem2:null, chance:0.1 },
"baked_potato": { elem2:null, chance:0.15 },
"bread": { elem2:null, chance:0.1 },
"toast": { elem2:null, chance:0.1 },
"gingerbread": { elem2:null, chance:0.1 },
"baked_batter": { elem2:null, chance:0.2 },
"wheat": { elem2:null, chance:0.1 },
"candy": { elem2:null, chance:0.1 },
"yogurt": { elem2:null, chance:0.2 },
"frozen_yogurt": { elem2:null, chance:0.1 },
"ice_cream": { elem2:null, chance:0.2 },
"beans": { elem2:[null,null,null,null,null,null,null,null,"stench"], chance:0.2 },
"tea": { elem2:null, chance:0.2 },
"coffee": { elem2:null, chance:0.2 },
"milk": { elem2:null, chance:0.2 },
"cream": { elem2:null, chance:0.2 },
"soda": { elem2:null, chance:0.2 },
"chocolate_milk": { elem2:null, chance:0.2 },
"fruit_milk": { elem2:null, chance:0.2 },
"pilk": { elem2:null, chance:0.2 },
"eggnog": { elem2:null, chance:0.2 },
"juice": { elem2:null, chance:0.2 },
"cheese": { elem2:null, chance:0.1 },
"melted_cheese": { elem2:null, chance:0.2 },
"alcohol": { elem2:null, chance:0.2 },
"antidote": { elem2:null, chance:0.2 },
"honey": { elem2:null, chance:0.2 },
"caramel": { elem2:null, chance:0.2 },
"molasses": { elem2:null, chance:0.05 },
"ketchup": { elem2:null, chance:0.1 },
"pumpkin_seed": { elem2:null, chance:0.1 },
"nut": { elem2:null, chance:0.1 },
"nut_meat": { elem2:null, chance:0.1 },
"nut_butter": { elem2:null, chance:0.1 },
"nut_milk": { elem2:null, chance:0.2 },
"jelly": { elem2:null, chance:0.2 },
"mayo": { elem2:null, chance:0.2 },
"mashed_potato": { elem2:null, chance:0.2 },
"sauce": { elem2:null, chance:0.2 },
"pickle": { elem2:null, chance:0.1 },
"sun": { elem1:"cooked_meat" },
"light": { stain1:"#825043" },
"bee": { stain1:"#cc564b", chance:0.2 },
"water": { elem2:"bubble", attr2:{"clone":"water"}, chance:0.001 },
"salt_water": { elem2:"bubble", attr2:{"clone":"salt_water"}, chance:0.001 },
"pool_water": { elem2:"bubble", attr2:{"clone":"pool_water"}, chance:0.001 },
},
properties: {
dead: false,
dir: 1,
panic: 0
},
}