The-Powder-Toy/src/simulation/elements/PHOT.cpp

136 lines
3.1 KiB
C++
Raw Normal View History

2012-05-07 11:59:50 -05:00
#include "simulation/Elements.h"
//#TPT-Directive ElementClass Element_PHOT PT_PHOT 31
Element_PHOT::Element_PHOT()
{
Identifier = "DEFAULT_PT_PHOT";
Name = "PHOT";
Colour = PIXPACK(0xFFFFFF);
MenuVisible = 1;
MenuSection = SC_NUCLEAR;
Enabled = 1;
Advection = 0.0f;
AirDrag = 0.00f * CFDS;
AirLoss = 1.00f;
Loss = 1.00f;
Collision = -0.99f;
Gravity = 0.0f;
Diffusion = 0.00f;
HotAir = 0.000f * CFDS;
Falldown = 0;
Flammable = 0;
Explosive = 0;
Meltable = 0;
Hardness = 0;
Weight = -1;
Temperature = R_TEMP+900.0f+273.15f;
HeatConduct = 251;
Description = "Photons. Refracts through glass, scattered by quartz, and color-changed by different elements. Ignites flammable materials.";
State = ST_GAS;
Properties = TYPE_ENERGY|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC;
LowPressure = IPL;
LowPressureTransition = NT;
HighPressure = IPH;
HighPressureTransition = NT;
LowTemperature = ITL;
LowTemperatureTransition = NT;
HighTemperature = ITH;
HighTemperatureTransition = NT;
Update = &Element_PHOT::update;
Graphics = &Element_PHOT::graphics;
2012-05-07 11:59:50 -05:00
}
2012-01-08 11:39:03 -06:00
2012-05-07 11:59:50 -05:00
//#TPT-Directive ElementHeader Element_PHOT static int update(UPDATE_FUNC_ARGS)
int Element_PHOT::update(UPDATE_FUNC_ARGS)
{
int r, rx, ry;
2012-01-08 11:39:03 -06:00
float rr, rrr;
if (!(parts[i].ctype&0x3FFFFFFF)) {
2012-01-08 11:39:03 -06:00
sim->kill_part(i);
return 1;
}
2012-08-28 09:09:32 -05:00
if (parts[i].temp > 506)
2013-02-27 16:20:05 -06:00
if (!(rand()%10)) Element_FIRE::update(UPDATE_FUNC_SUBCALL_ARGS);
2012-01-08 11:39:03 -06:00
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++)
if (BOUNDS_CHECK) {
2012-01-08 11:39:03 -06:00
r = pmap[y+ry][x+rx];
if (!r)
continue;
if ((r&0xFF)==PT_ISOZ || (r&0xFF)==PT_ISZS)
2012-01-08 11:39:03 -06:00
{
if (!(rand()%400))
{
parts[i].vx *= 0.90;
parts[i].vy *= 0.90;
sim->create_part(r>>8, x+rx, y+ry, PT_PHOT);
rrr = (rand()%360)*3.14159f/180.0f;
if ((r&0xFF) == PT_ISOZ)
rr = (rand()%128+128)/127.0f;
else
rr = (rand()%228+128)/127.0f;
parts[r>>8].vx = rr*cosf(rrr);
parts[r>>8].vy = rr*sinf(rrr);
sim->pv[y/CELL][x/CELL] -= 15.0f * CFDS;
}
2012-01-08 11:39:03 -06:00
}
else if((r&0xFF) == PT_QRTZ && !ry && !rx)//if on QRTZ
2012-01-08 11:39:03 -06:00
{
float a = (rand()%360)*3.14159f/180.0f;
parts[i].vx = 3.0f*cosf(a);
parts[i].vy = 3.0f*sinf(a);
if(parts[i].ctype == 0x3FFFFFFF)
parts[i].ctype = 0x1F<<(rand()%26);
parts[i].life++; //Delay death
2012-01-08 11:39:03 -06:00
}
else if ((r&0xFF) == PT_FILT && parts[r>>8].tmp==9)
{
parts[i].vx += ((float)(rand()%1000-500))/1000.0f;
parts[i].vy += ((float)(rand()%1000-500))/1000.0f;
}
2012-01-08 11:39:03 -06:00
}
return 0;
}
2012-05-07 11:59:50 -05:00
//#TPT-Directive ElementHeader Element_PHOT static int graphics(GRAPHICS_FUNC_ARGS)
int Element_PHOT::graphics(GRAPHICS_FUNC_ARGS)
2012-01-08 11:39:03 -06:00
{
int x = 0;
*colr = *colg = *colb = 0;
for (x=0; x<12; x++) {
*colr += (cpart->ctype >> (x+18)) & 1;
*colb += (cpart->ctype >> x) & 1;
}
for (x=0; x<12; x++)
*colg += (cpart->ctype >> (x+9)) & 1;
x = 624/(*colr+*colg+*colb+1);
*colr *= x;
*colg *= x;
*colb *= x;
*firea = 100;
*firer = *colr;
*fireg = *colg;
*fireb = *colb;
2012-10-01 15:54:52 -05:00
*pixel_mode &= ~PMODE_FLAT;
*pixel_mode |= FIRE_ADD | PMODE_ADD | NO_DECO;
2014-08-05 16:09:34 -05:00
if (cpart->flags & FLAG_PHOTDECO)
{
*pixel_mode &= ~NO_DECO;
}
2012-01-08 11:39:03 -06:00
return 0;
}
2012-05-07 11:59:50 -05:00
2013-02-27 16:20:05 -06:00
Element_PHOT::~Element_PHOT() {}