-
-
Save simtr/1927c64817b5ac9b55a6dca68fdb8ea0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "simulation/ElementCommon.h" | |
#define FLAG_TICKED 0x0100 | |
static int update(UPDATE_FUNC_ARGS); | |
static int graphics(GRAPHICS_FUNC_ARGS); | |
static void create(ELEMENT_CREATE_FUNC_ARGS); | |
void Element::Element_NDMD() | |
{ | |
Identifier = "DEFAULT_PT_NDMD"; | |
Name = "NDMD"; | |
Colour = PIXPACK(0xCCFFFF); | |
MenuVisible = 1; | |
MenuSection = SC_SOLIDS; | |
Enabled = 1; | |
Advection = 0.0f; | |
AirDrag = 0.00f * CFDS; | |
AirLoss = 0.90f; | |
Loss = 0.00f; | |
Collision = 0.0f; | |
Gravity = 0.0f; | |
Diffusion = 0.00f; | |
HotAir = 0.000f * CFDS; | |
Falldown = 0; | |
Flammable = 0; | |
Explosive = 0; | |
Meltable = 0; | |
Hardness = 0; | |
Weight = 100; | |
HeatConduct = 186; | |
Description = "Diamond. Very hard."; | |
Properties = TYPE_SOLID; | |
LowPressure = IPL; | |
LowPressureTransition = NT; | |
HighPressure = IPH; | |
HighPressureTransition = NT; | |
LowTemperature = ITL; | |
LowTemperatureTransition = NT; | |
HighTemperature = ITH; | |
HighTemperatureTransition = NT; | |
Update = &update; | |
Graphics = &graphics; | |
Create = &create; | |
} | |
static int update(UPDATE_FUNC_ARGS) | |
{ | |
int r, rx, ry; | |
if(parts[i].temp > 1400) { | |
float referenceTemp = parts[i].temp - 1400; | |
for (rx=-1; rx<2; rx++) | |
for (ry=-1; ry<2; ry++) | |
if (BOUNDS_CHECK && (rx || ry)) | |
{ | |
r = pmap[y+ry][x+rx]; | |
if (!r) | |
continue; | |
if ((TYP(r)==PT_O2 || TYP(r)==PT_LO2) && RNG::Ref().chance(referenceTemp, 50000)) | |
{ | |
sim->part_change_type(i, x, y, PT_CO2); | |
sim->part_change_type(ID(r), x+rx, y+ry, PT_CO2); | |
sim->pv[y/CELL][x/CELL] += 0.5; | |
} | |
} | |
} | |
if(parts[i].tmp2 > 0) { | |
int flagged = parts[i].tmp2 & FLAG_TICKED; | |
if(!flagged) { | |
parts[i].tmp2--; | |
for (rx=-1; rx<2; rx++) | |
for (ry=-1; ry<2; ry++) | |
if (BOUNDS_CHECK && (rx || ry) && (abs(rx) + abs(ry) < 2 )) | |
{ | |
r = pmap[y+ry][x+rx]; | |
if (!r) | |
continue; | |
if (TYP(r)==PT_NDMD && parts[ID(r)].life < parts[i].life-1) | |
{ | |
parts[ID(r)].tmp = parts[i].tmp; | |
parts[ID(r)].ctype = 0; | |
parts[ID(r)].life = parts[i].life-1; | |
parts[ID(r)].tmp2 = parts[i].tmp2 | FLAG_TICKED; | |
} else if(TYP(r)==PT_NDMD && parts[ID(r)].life > parts[i].life+2) { | |
parts[i].ctype = RNG::Ref().between(0, 8); | |
} | |
} | |
} else { | |
parts[i].tmp2 &= ~FLAG_TICKED; | |
} | |
} | |
return 0; | |
} | |
static int graphics(GRAPHICS_FUNC_ARGS) | |
{ | |
float glowStart = 1000.0f; | |
float glowEnd = 1800.0f; | |
float diff = glowEnd - glowStart; | |
int caddress = (cpart->tmp % 199) * 3; | |
if(cpart->tmp > 400) { | |
*colr = (unsigned char)ren->flm_data[caddress]; | |
*colg = (unsigned char)ren->flm_data[caddress+1]; | |
*colb = (unsigned char)ren->flm_data[caddress+2]; | |
} else { | |
*colr = (unsigned char)ren->plasma_data[caddress]; | |
*colg = (unsigned char)ren->plasma_data[caddress+1]; | |
*colb = (unsigned char)ren->plasma_data[caddress+2]; | |
} | |
if(cpart->temp > glowStart) { | |
double gradv = 3.1415f/(2.0f*glowEnd-glowStart); | |
int normalTemp = int((cpart->temp>glowEnd)?glowEnd-glowStart:cpart->temp-glowStart); | |
*colr += int(sin(gradv*normalTemp) * 226.0f); | |
*colg += int(sin(gradv*normalTemp*4.55f +3.14f) * 34.0f); | |
*colb += int(sin(gradv*normalTemp*2.22f +3.14f) * 64.0f); | |
*firea = normalTemp / (diff/64.0f); | |
*firer += int(sin(gradv*normalTemp) * 226.0f); | |
*fireg += int(sin(gradv*normalTemp*4.55f +3.14f) * 34.0f); | |
*fireb += int(sin(gradv*normalTemp*2.22f +3.14f) * 64.0f); | |
*pixel_mode |= FIRE_ADD; | |
} | |
if(cpart->ctype == 4) { | |
*pixel_mode |= PMODE_FLARE; | |
} | |
return 0; | |
} | |
static void create(ELEMENT_CREATE_FUNC_ARGS) | |
{ | |
sim->parts[i].life = RNG::Ref().between(1, 1024); | |
sim->parts[i].tmp = RNG::Ref().between(0, 600); | |
sim->parts[i].tmp2 = RNG::Ref().between(0, 8); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment