reformat ARAY.cpp because coding style was really hard to read

This commit is contained in:
jacob1
2015-11-22 00:12:04 -05:00
parent d1dcae5574
commit 7a78b91f4f

View File

@@ -49,62 +49,80 @@ Element_ARAY::Element_ARAY()
//#TPT-Directive ElementHeader Element_ARAY static int update(UPDATE_FUNC_ARGS) //#TPT-Directive ElementHeader Element_ARAY static int update(UPDATE_FUNC_ARGS)
int Element_ARAY::update(UPDATE_FUNC_ARGS) int Element_ARAY::update(UPDATE_FUNC_ARGS)
{ {
int r, nxx, nyy, docontinue, nxi, nyi, rx, ry, ry1, rx1; if (!parts[i].life)
if (parts[i].life==0) { {
for (rx=-1; rx<2; rx++) for (int rx = -1; rx <= 1; rx++)
for (ry=-1; ry<2; ry++) for (int ry = -1; ry <= 1; ry++)
if (BOUNDS_CHECK && (rx || ry)) if (BOUNDS_CHECK && (rx || ry))
{ {
r = pmap[y+ry][x+rx]; int r = pmap[y+ry][x+rx];
if (!r) if (!r)
continue; continue;
if ((r&0xFF)==PT_SPRK && parts[r>>8].life==3) { if ((r&0xFF) == PT_SPRK && parts[r>>8].life == 3)
{
bool isBlackDeco = false; bool isBlackDeco = false;
int destroy = (parts[r>>8].ctype==PT_PSCN)?1:0; int destroy = (parts[r>>8].ctype==PT_PSCN) ? 1 : 0;
int nostop = (parts[r>>8].ctype==PT_INST)?1:0; int nostop = (parts[r>>8].ctype==PT_INST) ? 1 : 0;
int colored = 0, rt; int colored = 0, rt;
for (docontinue = 1, nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1; docontinue; nyy+=nyi, nxx+=nxi) { for (int 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)) { {
if (!(x+nxi+nxx<XRES && y+nyi+nyy<YRES && x+nxi+nxx >= 0 && y+nyi+nyy >= 0))
break; break;
}
r = pmap[y+nyi+nyy][x+nxi+nxx]; r = pmap[y+nyi+nyy][x+nxi+nxx];
rt = r & 0xFF; rt = r & 0xFF;
r = r >> 8; r = r >> 8;
if (!rt) { if (!rt)
{
int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_BRAY); int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_BRAY);
if (nr!=-1) { if (nr != -1)
if (destroy) {//if it came from PSCN {
// if it came from PSCN
if (destroy)
{
parts[nr].tmp = 2; parts[nr].tmp = 2;
parts[nr].life = 2; parts[nr].life = 2;
} else }
else
parts[nr].ctype = colored; parts[nr].ctype = colored;
parts[nr].temp = parts[i].temp; parts[nr].temp = parts[i].temp;
if (isBlackDeco) if (isBlackDeco)
parts[nr].dcolour = 0xFF000000; parts[nr].dcolour = 0xFF000000;
} }
} else if (!destroy) { }
if (rt==PT_BRAY) { else if (!destroy)
//cases for hitting different BRAY modes {
switch(parts[r].tmp) { if (rt == PT_BRAY)
case 0://normal white {
if (nyy!=0 || nxx!=0) { // cases for hitting different BRAY modes
parts[r].life = 1020;//makes it last a while switch(parts[r].tmp)
{
// normal white
case 0:
if (nyy != 0 || nxx !=0)
{
parts[r].life = 1020; // makes it last a while
parts[r].tmp = 1; parts[r].tmp = 1;
if (!parts[r].ctype)//and colors it if it isn't already if (!parts[r].ctype) // and colors it if it isn't already
parts[r].ctype = colored; parts[r].ctype = colored;
} }
case 2://red bray, stop // red bray or any other random tmp mode, stop
default://stop any other random tmp mode case 2:
docontinue = 0;//then stop it default:
docontinue = 0;
break; break;
case 1://long life, reset it // long life, reset it
case 1:
parts[r].life = 1020; parts[r].life = 1020;
//docontinue = 1; //docontinue = 1;
break; break;
} }
if (isBlackDeco) if (isBlackDeco)
parts[r].dcolour = 0xFF000000; parts[r].dcolour = 0xFF000000;
} else if (rt==PT_FILT) {//get color if passed through FILT }
// get color if passed through FILT
else if (rt == PT_FILT)
{
if (parts[r].tmp != 6) if (parts[r].tmp != 6)
{ {
colored = Element_FILT::interactWavelengths(&parts[r], colored); colored = Element_FILT::interactWavelengths(&parts[r], colored);
@@ -113,13 +131,16 @@ int Element_ARAY::update(UPDATE_FUNC_ARGS)
} }
isBlackDeco = (parts[r].dcolour==0xFF000000); isBlackDeco = (parts[r].dcolour==0xFF000000);
parts[r].life = 4; parts[r].life = 4;
//this if prevents BRAY from stopping on certain materials }
} else if (rt == PT_STOR) { else if (rt == PT_STOR)
{
if (parts[r].tmp) if (parts[r].tmp)
{ {
//Cause STOR to release //Cause STOR to release
for (ry1 = 1; ry1 >= -1; ry1--){ for (int ry1 = 1; ry1 >= -1; ry1--)
for (rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1 - rx1 + 1){ {
for (int 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); int np = sim->create_part(-1, x + nxi + nxx + rx1, y + nyi + nyy + ry1, parts[r].tmp);
if (np != -1) if (np != -1)
{ {
@@ -138,37 +159,46 @@ int Element_ARAY::update(UPDATE_FUNC_ARGS)
{ {
parts[r].life = 10; 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)) { // this if prevents BRAY from stopping on certain materials
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;
}
} }
} else if (destroy) { 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 (rt==PT_BRAY) { {
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;
}
}
else if (destroy)
{
if (rt == PT_BRAY)
{
parts[r].tmp = 2; parts[r].tmp = 2;
parts[r].life = 1; parts[r].life = 1;
docontinue = 1; docontinue = 1;
if (isBlackDeco) if (isBlackDeco)
parts[r].dcolour = 0xFF000000; parts[r].dcolour = 0xFF000000;
//this if prevents red BRAY from stopping on certain materials //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) 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)
{ {
parts[r].tmp = 0; parts[r].tmp = 0;
parts[r].life = 0; parts[r].life = 0;
} }
else if (rt==PT_FILT) else if (rt == PT_FILT)
{ {
isBlackDeco = (parts[r].dcolour==0xFF000000); isBlackDeco = (parts[r].dcolour==0xFF000000);
parts[r].life = 2; parts[r].life = 2;
} }
docontinue = 1; docontinue = 1;
} else { }
else
{
docontinue = 0; docontinue = 0;
} }
} }