Skip to content

Commit

Permalink
Made walls invincible
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwijuice56 committed Feb 10, 2024
1 parent a5b841f commit a39457e
Show file tree
Hide file tree
Showing 20 changed files with 201 additions and 40 deletions.
Binary file modified .sconsign.dblite
Binary file not shown.
2 changes: 2 additions & 0 deletions extension/elements/all_elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
#include "elements/chemical/silver.h"
#include "elements/chemical/molten_silver.h"
#include "elements/chemical/lead.h"
#include "elements/chemical/base.h"

class AllElements {
public:
Expand Down Expand Up @@ -285,6 +286,7 @@ class AllElements {
elements->at(133) = new Silver();
elements->at(134) = new MoltenSilver();
elements->at(135) = new Lead();
elements->at(136) = new Base();

for (int i = 2048; i <= 4096; i++) {
elements->at(i) = new CustomElementParticle();
Expand Down
12 changes: 11 additions & 1 deletion extension/elements/chemical/acid.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ class Acid: public Element {
const double DECAY = 1.0 / 2048;
const double EVAPORATE = 1.0 / 64;
const double EAT = 1.0 / 16;
const double MIX = 1.0 / 4;
const double EMIT = 1.0 / 64;
const double DOWN = 1.0 / 1.2;
const double DOWN_BLOCK = 1.0 / 16;
const double MIX = 1.0 / 2;
const double REACT = 1.0 / 2;

void process(SandSimulation *sim, int row, int col) override {
// Decay
Expand Down Expand Up @@ -55,6 +56,15 @@ class Acid: public Element {

if (sim->randf() < EMIT)
sim->grow(row - 1, col, 0, 22);

if (sim->randf() < MIX && sim->touch_count(row, col, 136) > 0) {
sim->set_cell(row, col, 3);
}

if (sim->randf() < REACT && sim->touch_count(row, col, 17) + sim->touch_count(row, col, 51) + sim->touch_count(row, col, 133) + sim->touch_count(row, col, 135) + sim->touch_count(row, col, 45) + sim->touch_count(row, col, 35) > 0) {
sim->set_cell(row, col, 70);
sim->grow(row - 1, col, -1, 47);
}
}

double get_density() override {
Expand Down
5 changes: 5 additions & 0 deletions extension/elements/chemical/acid_water.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AcidWater: public Element {
const double EMIT = 1.0 / 64;
const double DOWN = 1.0 / 1.2;
const double DOWN_BLOCK = 1.0 / 16;
const double MIX = 1.0 / 4;

void process(SandSimulation *sim, int row, int col) override {
// Decay
Expand Down Expand Up @@ -53,6 +54,10 @@ class AcidWater: public Element {
sim->set_cell(row, col, sim->randf() < EMIT ? 22 : 0);
}

if (sim->randf() < MIX && sim->touch_count(row, col, 136) > 0) {
sim->set_cell(row, col, 3);
}

if (sim->randf() < EMIT)
sim->grow(row - 1, col, 0, 22);
}
Expand Down
78 changes: 78 additions & 0 deletions extension/elements/chemical/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#ifndef BASE_H
#define BASE_H

#include "../element.h"

class Base: public Element {
public:
const double DECAY = 1.0 / 4098;
const double EVAPORATE = 1.0 / 64;
const double EAT = 1.0 / 16;
const double EMIT = 1.0 / 64;
const double DOWN = 1.0 / 1.2;
const double DOWN_BLOCK = 1.0 / 16;
const double MIX = 1.0 / 2;
const double REACT = 1.0 / 2;

void process(SandSimulation *sim, int row, int col) override {
// Decay
if (sim->randf() < DECAY) {
sim->set_cell(row, col, 22);
return;
}

sim->liquid_process(row, col, 2);

bool blocked = !sim->in_bounds(row + 1, col) || sim->get_cell(row + 1, col) == 3;
int new_row = row, new_col = col;

if (sim->randf() < (blocked ? DOWN_BLOCK : DOWN))
new_row++;
else
new_col += sim->randf() < 0.5 ? 1 : -1;

// Ensure that the swallowed cell is in bounds and not base
if (!sim->in_bounds(new_row, new_col) || sim->get_cell(new_row, new_col) == 133)
return;

// Swap and delete
if (sim->get_cell(new_row, new_col) == 0 || sim->randf() < EAT * (1.0 - sim->elements.at(sim->get_cell(new_row, new_col))->get_acid_resistance())) {
sim->set_cell(new_row, new_col, sim->get_cell(row, col));
}

if (sim->randf() < MIX && sim->touch_count(row, col, 21) + sim->touch_count(row, col, 59) > 0) {
sim->set_cell(row, col, 3);
}

if (sim->randf() < REACT && sim->touch_count(row, col, 17) + sim->touch_count(row, col, 51) + sim->touch_count(row, col, 133) + sim->touch_count(row, col, 135) + sim->touch_count(row, col, 45) + sim->touch_count(row, col, 35) > 0) {
sim->set_cell(row, col, 70);
sim->grow(row - 1, col, -1, 47);
}
}

double get_density() override {
return 64.0;
}

double get_explode_resistance() override {
return 0.85;
}

double get_acid_resistance() override {
return 1.0;
}

int get_state() override {
return 1;
}

int get_temperature() override {
return 0;
}

int get_toxicity() override {
return 1;
}
};

#endif // BASE_H
3 changes: 3 additions & 0 deletions extension/elements/chemical/molten_silver.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MoltenSilver: public Element {
const double DOWN = 1.0 / 1.5;
const double COOL = 1.0 / 128;
const double REG_COOL = 1.0 / 1900;
const double EXPLODE = 1.0 / 2;

void process(SandSimulation *sim, int row, int col) override {
// Conductivity
Expand All @@ -22,6 +23,8 @@ class MoltenSilver: public Element {
if (sim->randf() < COOL && (sim->is_cold(row, col) || sim->touch_count(row, col, 0) > 0) || sim->randf() < REG_COOL) {
sim->set_cell(row, col, 133);
return;
} else if (sim->randf() < EXPLODE && sim->touch_count(row, col, 23) + sim->touch_count(row, col, 32) > 0) {
sim->set_cell(row, col, 9);
}

sim->liquid_process(row, col, 3);
Expand Down
9 changes: 6 additions & 3 deletions extension/elements/chemical/silver.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@

#include "../element.h"

class GoSilverld: public Element {
class Silver: public Element {
public:
const double PLASMA = 1.0 / 8;
const double MELT = 1.0 / 32;
const double EXPLODE = 1.0 / 90;
const double EXPLODE = 1.0 / 16;

void process(SandSimulation *sim, int row, int col) override {
if (sim->randf() < PLASMA && (sim->touch_count(row, col, 38) > 0 || sim->touch_count(row, col, 40) > 0 || sim->touch_count(row, col, 115) > 0)) {
sim->grow(row + 1, col, 133, 38);
sim->grow(row - 1, col, 133, 38);
sim->grow(row, col - 1, 133, 38);
sim->grow(row, col + 1, 133, 38);
return;
} else if (sim -> randf() < MELT && (sim->touch_count(row, col, 20) + sim->touch_count(row, col, 24) > 0)) {
} else if (sim->randf() < MELT && (sim->touch_count(row, col, 20) + sim->touch_count(row, col, 24) > 0)) {
sim->set_cell(row, col, 134);
} else if (sim->randf() < EXPLODE && sim->touch_count(row, col, 23) + sim->touch_count(row, col, 32) > 0) {
sim->set_cell(row, col, 9);
}
}

Expand Down
2 changes: 1 addition & 1 deletion extension/elements/space/black_hole.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BlackHole: public Element {
// Absorb anything in immediate proximity if not a black hole
for (int y = row - 1; y <= row + 1; y++) {
for (int x = col - 1; x <= col + 1; x++) {
if (sim->in_bounds(y, x) && sim->get_cell(y, x) != 29) {
if (sim->in_bounds(y, x) && sim->get_cell(y, x) != 29 && sim->get_cell(y, x) != 15) {
sim->set_cell(y, x, 0);
}
}
Expand Down
4 changes: 4 additions & 0 deletions extension/elements/space/paradox.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Paradox: public Element {
int r = std::min(sim->get_height() - 1, (int) (sim->randf() * sim->get_height()));
if (!sim->in_bounds(r, c) || !sim->in_bounds(y, x))
continue;
if (sim->get_cell(r, c) == 15 || sim->get_cell(y, x) == 15)
return;

int temp = sim->get_cell(y, x);
sim->set_cell(y, x, sim->get_cell(r, c));
Expand All @@ -46,6 +48,8 @@ class Paradox: public Element {
if (col == x) dirCol = 0;
if (!sim->in_bounds(y + dirRow, x + dirCol))
return;
if (sim->get_cell(y + dirRow, x + dirCol) == 15 || sim->get_cell(y, x) == 15)
return;
int temp = sim->get_cell(y, x);
sim->set_cell(y, x, sim->get_cell(y + dirRow, x + dirCol));
sim->set_cell(y + dirRow, x + dirCol, temp);
Expand Down
7 changes: 5 additions & 2 deletions extension/elements/space/worm_hole.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class WormHole: public Element {
int r = std::min(sim->get_height() - 1, (int) (sim->randf() * sim->get_height()));
if (!sim->in_bounds(r, c) || !sim->in_bounds(y, x) || sim->get_cell(y, x) == 0 || sim->get_cell(y, x) == 81 || sim->get_cell(r, c) == 81)
continue;

if (sim->get_cell(r, c) == 15 || sim->get_cell(y, x) == 15)
continue;

int temp = sim->get_cell(y, x);
sim->set_cell(y, x, sim->get_cell(r, c));
Expand All @@ -37,7 +40,7 @@ class WormHole: public Element {
// Keep moving particles closer into the worm hole
for (int y = row - 8; y <= row + 8; y++) {
for (int x = col - 8; x <= col + 8; x++) {
if (sim->randf() >= GRAB || !sim->in_bounds(y, x) || sim->get_cell(y, x) == 81)
if (sim->randf() >= GRAB || !sim->in_bounds(y, x) || sim->get_cell(y, x) == 81 || sim->get_cell(y, x) == 15)
continue;
if (sim->get_cell(y, x) == 29)
sim->set_cell(y, x, 116);
Expand All @@ -46,7 +49,7 @@ class WormHole: public Element {
int dirCol = col - x < 0 ? -1 : 1;
if (row == y) dirRow = 0;
if (col == x) dirCol = 0;
if (!sim->in_bounds(y + dirRow, x + dirCol) || sim->get_cell(y + dirRow, x + dirCol) == 81)
if (!sim->in_bounds(y + dirRow, x + dirCol) || sim->get_cell(y + dirRow, x + dirCol) == 81 || sim->get_cell(y + dirRow, x + dirCol) == 15)
return;
int temp = sim->get_cell(y, x);
sim->set_cell(y, x, sim->get_cell(y + dirRow, x + dirCol));
Expand Down
10 changes: 9 additions & 1 deletion extension/sand_simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ void SandSimulation::step(int iterations) {
void SandSimulation::move_and_swap(int row, int col, int row2, int col2) {
if (!in_bounds(row, col) || !in_bounds(row2, col2))
return;
if (get_cell(row, col) == 15 || get_cell(row2, col2) == 15) {
return;
}
if (elements[get_cell(row2, col2)]->get_state() == 0)
return;
if (elements[get_cell(row, col)]->get_state() != 0)
Expand All @@ -93,6 +96,7 @@ void SandSimulation::move_and_swap(int row, int col, int row2, int col2) {
void SandSimulation::grow(int row, int col, int food, int replacer) {
if (!in_bounds(row, col))
return;

if (food == -1) {
// Since only explosions/lasers grow into all cells, we run a check for explosion resistance
if (randf() >= (1.0 - elements[get_cell(row, col)]->get_explode_resistance()))
Expand Down Expand Up @@ -221,7 +225,11 @@ int SandSimulation::get_cell(int row, int col) {
return cells[row * width + col];
}

void SandSimulation::set_cell(int row, int col, int type) {
void SandSimulation::set_cell(int row, int col, int type) {
if (get_cell(row, col) == 15 && type != 0) {
return;
}

if (cells[row * width + col] == 0 && type != 0)
chunks[(row / chunk_size) * chunk_width + (col / chunk_size)]++;
else if (cells[row * width + col] != 0 && type == 0)
Expand Down
Binary file modified extension/sand_simulation.windows.template_debug.x86_64.obj
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit a39457e

Please sign in to comment.