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

185 lines
5.4 KiB
C++
Raw Normal View History

2012-05-07 11:59:50 -05:00
#include "simulation/Elements.h"
//#TPT-Directive ElementClass Element_ARAY PT_ARAY 126
Element_ARAY::Element_ARAY()
{
Identifier = "DEFAULT_PT_ARAY";
Name = "ARAY";
Colour = PIXPACK(0xFFBB00);
MenuVisible = 1;
MenuSection = SC_ELEC;
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 = 1;
Weight = 100;
Temperature = R_TEMP+0.0f +273.15f;
HeatConduct = 0;
Description = "Ray Emitter. Rays create points when they collide.";
State = ST_SOLID;
Properties = TYPE_SOLID|PROP_LIFE_DEC;
LowPressure = IPL;
LowPressureTransition = NT;
HighPressure = IPH;
HighPressureTransition = NT;
LowTemperature = ITL;
LowTemperatureTransition = NT;
HighTemperature = ITH;
HighTemperatureTransition = NT;
Update = &Element_ARAY::update;
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_ARAY static int update(UPDATE_FUNC_ARGS)
int Element_ARAY::update(UPDATE_FUNC_ARGS)
{
int r, nxx, nyy, docontinue, nxi, nyi, rx, ry, ry1, rx1;
2012-01-08 11:39:03 -06:00
if (parts[i].life==0) {
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++)
if (BOUNDS_CHECK && (rx || ry))
2012-01-08 11:39:03 -06:00
{
r = pmap[y+ry][x+rx];
if (!r)
continue;
if ((r&0xFF)==PT_SPRK && parts[r>>8].life==3) {
bool isBlackDeco = false;
2012-01-08 11:39:03 -06:00
int destroy = (parts[r>>8].ctype==PT_PSCN)?1:0;
int nostop = (parts[r>>8].ctype==PT_INST)?1:0;
int colored = 0, rt;
2012-01-08 11:39:03 -06:00
for (docontinue = 1, nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1; docontinue; nyy+=nyi, nxx+=nxi) {
if (!(x+nxi+nxx<XRES && y+nyi+nyy<YRES && x+nxi+nxx >= 0 && y+nyi+nyy >= 0)) {
break;
}
r = pmap[y+nyi+nyy][x+nxi+nxx];
rt = r & 0xFF;
r = r >> 8;
if (!rt) {
2012-01-08 11:39:03 -06:00
int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_BRAY);
if (nr!=-1) {
if (destroy) {//if it came from PSCN
parts[nr].tmp = 2;
parts[nr].life = 2;
} else
parts[nr].ctype = colored;
parts[nr].temp = parts[i].temp;
if (isBlackDeco)
parts[nr].dcolour = 0xFF000000;
2012-01-08 11:39:03 -06:00
}
} else if (!destroy) {
if (rt==PT_BRAY) {
//cases for hitting different BRAY modes
switch(parts[r].tmp) {
case 0://normal white
if (nyy!=0 || nxx!=0) {
parts[r].life = 1020;//makes it last a while
parts[r].tmp = 1;
if (!parts[r].ctype)//and colors it if it isn't already
parts[r].ctype = colored;
}
case 2://red bray, stop
default://stop any other random tmp mode
docontinue = 0;//then stop it
break;
case 1://long life, reset it
parts[r].life = 1020;
//docontinue = 1;
break;
2012-01-08 11:39:03 -06:00
}
if (isBlackDeco)
parts[r].dcolour = 0xFF000000;
} else if (rt==PT_FILT) {//get color if passed through FILT
if (parts[r].tmp != 6)
{
colored = Element_FILT::interactWavelengths(&parts[r], colored);
if (!colored)
break;
}
isBlackDeco = (parts[r].dcolour==0xFF000000);
parts[r].life = 4;
//this if prevents BRAY from stopping on certain materials
} else if (rt == PT_STOR) {
if (parts[r].tmp)
2012-01-08 11:39:03 -06:00
{
//Cause STOR to release
for (ry1 = 1; ry1 >= -1; ry1--){
for (rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1 - rx1 + 1){
int np = sim->create_part(-1, x + nxi + nxx + rx1, y + nyi + nyy + ry1, parts[r].tmp);
if (np != -1)
2012-01-08 11:39:03 -06:00
{
parts[np].temp = parts[r].temp;
parts[np].life = parts[r].tmp2;
parts[np].tmp = parts[r].pavg[0];
parts[np].ctype = parts[r].pavg[1];
parts[r].tmp = 0;
parts[r].life = 10;
2012-01-08 11:39:03 -06:00
break;
}
}
}
}
else
{
parts[r].life = 10;
}
} else if (rt != PT_INWR && (rt != PT_SPRK || parts[r].ctype != PT_INWR) && rt != PT_ARAY && rt != PT_WIFI && !(rt == PT_SWCH && parts[r].life >= 10)) {
if (nyy!=0 || nxx!=0) {
sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_SPRK);
}
if (!(nostop && parts[r].type==PT_SPRK && parts[r].ctype >= 0 && parts[r].ctype < PT_NUM && (sim->elements[parts[r].ctype].Properties&PROP_CONDUCTS))) {
docontinue = 0;
} else {
docontinue = 1;
2012-01-08 11:39:03 -06:00
}
}
} else if (destroy) {
if (rt==PT_BRAY) {
parts[r].tmp = 2;
parts[r].life = 1;
2012-01-08 11:39:03 -06:00
docontinue = 1;
if (isBlackDeco)
parts[r].dcolour = 0xFF000000;
//this if prevents red BRAY from stopping on certain materials
} else if (rt==PT_STOR || rt==PT_INWR || (rt==PT_SPRK && parts[r].ctype==PT_INWR) || rt==PT_ARAY || rt==PT_WIFI || rt==PT_FILT || (rt==PT_SWCH && parts[r].life>=10)) {
if(rt==PT_STOR)
2012-01-08 11:39:03 -06:00
{
parts[r].tmp = 0;
parts[r].life = 0;
2012-01-08 11:39:03 -06:00
}
else if (rt==PT_FILT)
{
isBlackDeco = (parts[r].dcolour==0xFF000000);
parts[r].life = 2;
}
2012-01-08 11:39:03 -06:00
docontinue = 1;
} else {
docontinue = 0;
}
}
}
}
//parts[i].life = 4;
}
}
return 0;
}
2012-05-07 11:59:50 -05:00
2013-02-28 11:37:16 -06:00
Element_ARAY::~Element_ARAY() {}