Skip to content

Commit

Permalink
reformat ARAY.cpp because coding style was really hard to read
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Nov 22, 2015
1 parent d1dcae5 commit 7a78b91
Showing 1 changed file with 74 additions and 44 deletions.
118 changes: 74 additions & 44 deletions src/simulation/elements/ARAY.cpp
Expand Up @@ -49,62 +49,80 @@ Element_ARAY::Element_ARAY()
//#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;
if (parts[i].life==0) {
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++)
if (!parts[i].life)
{
for (int rx = -1; rx <= 1; rx++)
for (int ry = -1; ry <= 1; ry++)
if (BOUNDS_CHECK && (rx || ry))
{
r = pmap[y+ry][x+rx];
int r = pmap[y+ry][x+rx];
if (!r)
continue;
if ((r&0xFF)==PT_SPRK && parts[r>>8].life==3) {
if ((r&0xFF) == PT_SPRK && parts[r>>8].life == 3)
{
bool isBlackDeco = false;
int destroy = (parts[r>>8].ctype==PT_PSCN)?1:0;
int nostop = (parts[r>>8].ctype==PT_INST)?1:0;
int destroy = (parts[r>>8].ctype==PT_PSCN) ? 1 : 0;
int nostop = (parts[r>>8].ctype==PT_INST) ? 1 : 0;
int colored = 0, rt;
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)) {
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))
break;
}

r = pmap[y+nyi+nyy][x+nxi+nxx];
rt = r & 0xFF;
r = r >> 8;
if (!rt) {
if (!rt)
{
int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_BRAY);
if (nr!=-1) {
if (destroy) {//if it came from PSCN
if (nr != -1)
{
// if it came from PSCN
if (destroy)
{
parts[nr].tmp = 2;
parts[nr].life = 2;
} else
}
else
parts[nr].ctype = colored;
parts[nr].temp = parts[i].temp;
if (isBlackDeco)
parts[nr].dcolour = 0xFF000000;
}
} 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
}
else if (!destroy)
{
if (rt == PT_BRAY)
{
// cases for hitting different BRAY modes
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;
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;
}
case 2://red bray, stop
default://stop any other random tmp mode
docontinue = 0;//then stop it
// red bray or any other random tmp mode, stop
case 2:
default:
docontinue = 0;
break;
case 1://long life, reset it
// long life, reset it
case 1:
parts[r].life = 1020;
//docontinue = 1;
break;
}
if (isBlackDeco)
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)
{
colored = Element_FILT::interactWavelengths(&parts[r], colored);
Expand All @@ -113,13 +131,16 @@ int Element_ARAY::update(UPDATE_FUNC_ARGS)
}
isBlackDeco = (parts[r].dcolour==0xFF000000);
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)
{
//Cause STOR to release
for (ry1 = 1; ry1 >= -1; ry1--){
for (rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1 - rx1 + 1){
for (int ry1 = 1; ry1 >= -1; ry1--)
{
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);
if (np != -1)
{
Expand All @@ -138,37 +159,46 @@ int Element_ARAY::update(UPDATE_FUNC_ARGS)
{
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) {
// this if prevents BRAY from stopping on certain materials
}
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))) {

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 {
else
docontinue = 1;
}
}
} else if (destroy) {
if (rt==PT_BRAY) {
}
else if (destroy)
{
if (rt == PT_BRAY)
{
parts[r].tmp = 2;
parts[r].life = 1;
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)
}
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].life = 0;
}
else if (rt==PT_FILT)
else if (rt == PT_FILT)
{
isBlackDeco = (parts[r].dcolour==0xFF000000);
parts[r].life = 2;
}
docontinue = 1;
} else {
}
else
{
docontinue = 0;
}
}
Expand Down

0 comments on commit 7a78b91

Please sign in to comment.