From b40f13b66a8661d8698e5fc737c2842dfb73e6f9 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Wed, 18 Apr 2012 21:18:37 +0100 Subject: [PATCH] TPT: Added gel - a liquid with variable heat conductivity and viscosity. 8523da398f --- src/elements/gel.cpp | 62 +++++++++++++++++++++++++++++++ src/simulation/ElementFunctions.h | 2 + src/simulation/Elements.h | 1 + src/simulation/Simulation.cpp | 34 +++++++++++------ src/simulation/SimulationData.cpp | 6 +-- 5 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 src/elements/gel.cpp diff --git a/src/elements/gel.cpp b/src/elements/gel.cpp new file mode 100644 index 000000000..9092097cb --- /dev/null +++ b/src/elements/gel.cpp @@ -0,0 +1,62 @@ +#include "simulation\Element.h" + +int update_GEL(UPDATE_FUNC_ARGS) { + int r, rx, ry; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + if (x+rx>=0 && y+ry>0 && x+rxkill_part(r>>8); + } + + char gel = 0; + if ((r&0xFF)==PT_GEL) + gel = 1; + + //Concentration diffusion + if (gel && (parts[r>>8].tmp+1)>8].tmp++; + parts[i].tmp--; + } + + float dx, dy; + dx = parts[i].x - parts[r>>8].x; + dy = parts[i].y - parts[r>>8].y; + + //Stickness + if ((dx*dx + dy*dy)>1.5 && (gel || !sim->ptypes[r&0xFF].falldown || (fabs(rx)<2 && fabs(ry)<2))) + { + float per, nd; + nd = dx*dx + dy*dy - 0.5; + + per = 5*(1 - parts[i].tmp/100)*(nd/(dx*dx + dy*dy + nd) - 0.5); + if (sim->ptypes[r&0xFF].state==ST_LIQUID) + per *= 0.1; + + dx *= per; dy *= per; + parts[i].vx += dx; parts[r>>8].vx -= dx; + parts[i].vy += dy; parts[r>>8].vy -= dy; + } + } + return 0; +} + +int graphics_GEL(GRAPHICS_FUNC_ARGS) +{ + int q = cpart->tmp; + *colr = q*(32-255)/120+255; + *colg = q*(48-186)/120+186; + *colb = q*208/120; + return 0; +} + diff --git a/src/simulation/ElementFunctions.h b/src/simulation/ElementFunctions.h index ad597b76d..7f864240a 100644 --- a/src/simulation/ElementFunctions.h +++ b/src/simulation/ElementFunctions.h @@ -108,6 +108,7 @@ int update_MISC(UPDATE_FUNC_ARGS); int update_FRAY(UPDATE_FUNC_ARGS); int update_REPL(UPDATE_FUNC_ARGS); int update_NBLE(UPDATE_FUNC_ARGS); +int update_GEL(UPDATE_FUNC_ARGS); int update_legacy_PYRO(UPDATE_FUNC_ARGS); int update_legacy_all(UPDATE_FUNC_ARGS); int run_stickman(playerst* playerp, UPDATE_FUNC_ARGS); @@ -166,6 +167,7 @@ int graphics_ELEC(GRAPHICS_FUNC_ARGS); int graphics_WIRE(GRAPHICS_FUNC_ARGS); int graphics_ACEL(GRAPHICS_FUNC_ARGS); int graphics_DCEL(GRAPHICS_FUNC_ARGS); +int graphics_GEL(GRAPHICS_FUNC_ARGS); int graphics_DEFAULT(GRAPHICS_FUNC_ARGS); #endif /* ELEMENTFUNCTIONS_H_ */ diff --git a/src/simulation/Elements.h b/src/simulation/Elements.h index 7d59dcb22..6a62c1140 100644 --- a/src/simulation/Elements.h +++ b/src/simulation/Elements.h @@ -262,6 +262,7 @@ #define PT_BANG 139 #define PT_IGNT 140 #define PT_BOYL 141 +#define PT_GEL 142 #define OLD_PT_WIND 147 #define PT_H2 148 diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index fdc94ab80..b08398ff8 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -1175,7 +1175,7 @@ void Simulation::init_can_move() for (rt=1;rt= 0 && y-2 < YRES && (ptypes[t].properties&TYPE_LIQUID)) {//some heat convection for liquids + if (y-2 >= 0 && y-2 < YRES && (ptypes[t].properties&TYPE_LIQUID) && gel_scale>(rand()%250)) {//some heat convection for liquids r = pmap[y-2][x]; if (!(!r || parts[i].type != (r&0xFF))) { if (parts[i].temp>parts[r>>8].temp) { @@ -2614,19 +2618,19 @@ void Simulation::update_particles_i(int start, int inc) //heat transfer code h_count = 0; #ifdef REALISTIC - if (t&&(t!=PT_HSWC||parts[i].life==10)&&ptypes[t].hconduct) + if (t&&(t!=PT_HSWC||parts[i].life==10)&&(ptypes[t].hconduct*gel_scale)) { float c_Cm = 0.0f; #else - if (t&&(t!=PT_HSWC||parts[i].life==10)&&ptypes[t].hconduct>(rand()%250)) + if (t&&(t!=PT_HSWC||parts[i].life==10)&&(ptypes[t].hconduct*gel_scale)>(rand()%250)) { float c_Cm = 0.0f; #endif if (aheat_enable) { #ifdef REALISTIC - c_heat = parts[i].temp*96.645/ptypes[t].hconduct*fabs(ptypes[t].weight) + hv[y/CELL][x/CELL]*100*(pv[y/CELL][x/CELL]+273.15f)/256; - c_Cm = 96.645/ptypes[t].hconduct*fabs(ptypes[t].weight) + 100*(pv[y/CELL][x/CELL]+273.15f)/256; + c_heat = parts[i].temp*96.645/ptypes[t].hconduct*gel_scale*fabs(ptypes[t].weight) + hv[y/CELL][x/CELL]*100*(pv[y/CELL][x/CELL]+273.15f)/256; + c_Cm = 96.645/ptypes[t].hconduct*gel_scale*fabs(ptypes[t].weight) + 100*(pv[y/CELL][x/CELL]+273.15f)/256; pt = c_heat/c_Cm; pt = restrict_flt(pt, -MAX_TEMP+MIN_TEMP, MAX_TEMP-MIN_TEMP); parts[i].temp = pt; @@ -2655,8 +2659,12 @@ void Simulation::update_particles_i(int start, int inc) { surround_hconduct[j] = r>>8; #ifdef REALISTIC - c_heat += parts[r>>8].temp*96.645/ptypes[rt].hconduct*fabs(ptypes[rt].weight); - c_Cm += 96.645/ptypes[rt].hconduct*fabs(ptypes[rt].weight); + if (rt==PT_GEL) + gel_scale = parts[r>>8].tmp*2.55f; + else gel_scale = 1.0f; + + c_heat += parts[r>>8].temp*96.645/ptypes[rt].hconduct*gel_scale*fabs(ptypes[rt].weight); + c_Cm += 96.645/ptypes[rt].hconduct*gel_scale*fabs(ptypes[rt].weight); #else c_heat += parts[r>>8].temp; #endif @@ -2664,13 +2672,17 @@ void Simulation::update_particles_i(int start, int inc) } } #ifdef REALISTIC + if (t==PT_GEL) + gel_scale = parts[i].tmp*2.55f; + else gel_scale = 1.0f; + if (t == PT_PHOT) pt = (c_heat+parts[i].temp*96.645)/(c_Cm+96.645); else - pt = (c_heat+parts[i].temp*96.645/ptypes[t].hconduct*fabs(ptypes[t].weight))/(c_Cm+96.645/ptypes[t].hconduct*fabs(ptypes[t].weight)); + pt = (c_heat+parts[i].temp*96.645/ptypes[t].hconduct*gel_scale*fabs(ptypes[t].weight))/(c_Cm+96.645/ptypes[t].hconduct*gel_scale*fabs(ptypes[t].weight)); - c_heat += parts[i].temp*96.645/ptypes[t].hconduct*fabs(ptypes[t].weight); - c_Cm += 96.645/ptypes[t].hconduct*fabs(ptypes[t].weight); + c_heat += parts[i].temp*96.645/ptypes[t].hconduct*gel_scale*fabs(ptypes[t].weight); + c_Cm += 96.645/ptypes[t].hconduct*gel_scale*fabs(ptypes[t].weight); parts[i].temp = restrict_flt(pt, MIN_TEMP, MAX_TEMP); #else pt = (c_heat+parts[i].temp)/(h_count+1); diff --git a/src/simulation/SimulationData.cpp b/src/simulation/SimulationData.cpp index 48dfb7c00..46f3ee628 100644 --- a/src/simulation/SimulationData.cpp +++ b/src/simulation/SimulationData.cpp @@ -331,7 +331,7 @@ part_type * LoadElements(int & elementCount) {"TNT", PIXPACK(0xC05050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 88, "Explosive.", ST_SOLID, TYPE_SOLID | PROP_NEUTPENETRATE, &update_BANG, NULL}, {"IGNC", PIXPACK(0xC0B050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 88, "Ignition cord.", ST_SOLID, TYPE_SOLID | PROP_NEUTPENETRATE | PROP_SPARKSETTLE | PROP_LIFE_KILL, &update_IGNT, NULL}, {"BOYL", PIXPACK(0x0A3200), 1.0f, 0.01f * CFDS, 0.99f, 0.30f, -0.1f, 0.0f, 0.18f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 1, SC_GAS, R_TEMP+2.0f +273.15f, 42, "Boyle, variable pressure gas. Expands when heated.", ST_GAS, TYPE_GAS, &update_BOYL, NULL}, - /*FREE*/{"LOTE", PIXPACK(0xFF0000), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 0, 0, 100, SC_LIFE, 9000.0f, 40, "Behaves kinda like Living on the Edge S3458/B37/4", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL, NULL}, + {"GEL", PIXPACK(0xFF9900), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 20, 1, 1, 35, SC_LIQUID, R_TEMP-2.0f +273.15f, 29, "Gel. A liquid with variable viscosity and heat conductivity", ST_LIQUID, TYPE_LIQUID|PROP_LIFE_DEC|PROP_NEUTPENETRATE, &update_GEL, &graphics_GEL}, /*FREE*/{"FRG2", PIXPACK(0x00FF00), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 0, 0, 100, SC_LIFE, 9000.0f, 40, "Like Frogs rule S124/B3/3", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL, NULL}, /*FREE*/{"STAR", PIXPACK(0x0000FF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 0, 0, 100, SC_LIFE, 9000.0f, 40, "Like Star Wars rule S3456/B278/6", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL, NULL}, /*FREE*/{"FROG", PIXPACK(0x00AA00), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 0, 0, 100, SC_LIFE, 9000.0f, 40, "Frogs S12/B34/3", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL, NULL}, @@ -504,7 +504,7 @@ unsigned int * LoadLatent(int & elementCount) /* TNT */ 0, /* IGNP */ 0, /* BOYL */ 0, - /* FREE */ 0, + /* GEL */ 0, /* FREE */ 0, /* FREE */ 0, /* FREE */ 0, @@ -685,7 +685,7 @@ part_transition * LoadTransitions(int & transitionCount) /* TNT */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT}, /* IGNP */ {IPL, NT, IPH, NT, ITL, NT, 673.0f, PT_FIRE}, /* BOYL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT}, - /*FREE*//* GOL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT}, + /* GEL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT}, /*FREE*//* GOL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT}, /*FREE*//* GOL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT}, /*FREE*//* GOL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},