mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-17 21:51:20 +02:00
replace some if-else with switch statements, code formatting, closes #444
This commit is contained in:
@@ -2184,17 +2184,17 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr)
|
|||||||
result = can_move[pt][r&0xFF];
|
result = can_move[pt][r&0xFF];
|
||||||
if (result == 3)
|
if (result == 3)
|
||||||
{
|
{
|
||||||
if ((r&0xFF) == PT_LCRY)
|
switch (r&0xFF)
|
||||||
{
|
{
|
||||||
|
case PT_LCRY:
|
||||||
if (pt==PT_PHOT || pt==PT_ELEC)
|
if (pt==PT_PHOT || pt==PT_ELEC)
|
||||||
result = (parts[r>>8].life > 5)? 2 : 0;
|
result = (parts[r>>8].life > 5)? 2 : 0;
|
||||||
}
|
break;
|
||||||
else if ((r&0xFF) == PT_GPMP)
|
case PT_GPMP:
|
||||||
{
|
|
||||||
if (pt == PT_PHOT)
|
if (pt == PT_PHOT)
|
||||||
result = (parts[r>>8].life < 10) ? 2 : 0;
|
result = (parts[r>>8].life < 10) ? 2 : 0;
|
||||||
}
|
break;
|
||||||
else if ((r&0xFF) == PT_INVIS)
|
case PT_INVIS:
|
||||||
{
|
{
|
||||||
float pressureResistance = 0.0f;
|
float pressureResistance = 0.0f;
|
||||||
if (parts[r>>8].tmp > 0)
|
if (parts[r>>8].tmp > 0)
|
||||||
@@ -2206,9 +2206,9 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr)
|
|||||||
result = 2;
|
result = 2;
|
||||||
else
|
else
|
||||||
result = 0;
|
result = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if ((r&0xFF) == PT_PVOD)
|
case PT_PVOD:
|
||||||
{
|
|
||||||
if (parts[r>>8].life == 10)
|
if (parts[r>>8].life == 10)
|
||||||
{
|
{
|
||||||
if (!parts[r>>8].ctype || (parts[r>>8].ctype==pt)!=(parts[r>>8].tmp&1))
|
if (!parts[r>>8].ctype || (parts[r>>8].ctype==pt)!=(parts[r>>8].tmp&1))
|
||||||
@@ -2217,21 +2217,27 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr)
|
|||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
else result = 0;
|
else result = 0;
|
||||||
}
|
break;
|
||||||
else if ((r&0xFF) == PT_VOID)
|
case PT_VOID:
|
||||||
{
|
|
||||||
if (!parts[r>>8].ctype || (parts[r>>8].ctype==pt)!=(parts[r>>8].tmp&1))
|
if (!parts[r>>8].ctype || (parts[r>>8].ctype==pt)!=(parts[r>>8].tmp&1))
|
||||||
result = 1;
|
result = 1;
|
||||||
else
|
else
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
break;
|
||||||
else if (pt == PT_TRON && (r&0xFF) == PT_SWCH)
|
case PT_SWCH:
|
||||||
|
if (pt == PT_TRON)
|
||||||
{
|
{
|
||||||
if (parts[r>>8].life >= 10)
|
if (parts[r>>8].life >= 10)
|
||||||
return 2;
|
return 2;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// This should never happen
|
||||||
|
// If it were to happen, try_move would interpret a 3 as a 1
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (bmap[ny/CELL][nx/CELL])
|
if (bmap[ny/CELL][nx/CELL])
|
||||||
{
|
{
|
||||||
@@ -2308,20 +2314,23 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
|
|||||||
|
|
||||||
if (e == 2) //if occupy same space
|
if (e == 2) //if occupy same space
|
||||||
{
|
{
|
||||||
if (parts[i].type == PT_PHOT)
|
switch (parts[i].type)
|
||||||
{
|
{
|
||||||
if ((r&0xFF) == PT_GLOW)
|
case PT_PHOT:
|
||||||
{
|
{
|
||||||
|
switch (r&0xFF)
|
||||||
|
{
|
||||||
|
case PT_GLOW:
|
||||||
if (!parts[r>>8].life && rand() < RAND_MAX/30)
|
if (!parts[r>>8].life && rand() < RAND_MAX/30)
|
||||||
{
|
{
|
||||||
parts[r>>8].life = 120;
|
parts[r>>8].life = 120;
|
||||||
create_gain_photon(i);
|
create_gain_photon(i);
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else if ((r&0xFF) == PT_FILT)
|
case PT_FILT:
|
||||||
parts[i].ctype = Element_FILT::interactWavelengths(&parts[r>>8], parts[i].ctype);
|
parts[i].ctype = Element_FILT::interactWavelengths(&parts[r>>8], parts[i].ctype);
|
||||||
else if ((r&0xFF) == PT_C5)
|
break;
|
||||||
{
|
case PT_C5:
|
||||||
if (parts[r>>8].life > 0 && (parts[r>>8].ctype & parts[i].ctype & 0xFFFFFFC0))
|
if (parts[r>>8].life > 0 && (parts[r>>8].ctype & parts[i].ctype & 0xFFFFFFC0))
|
||||||
{
|
{
|
||||||
float vx = ((parts[r>>8].tmp << 16) >> 16) / 255.0f;
|
float vx = ((parts[r>>8].tmp << 16) >> 16) / 255.0f;
|
||||||
@@ -2347,8 +2356,8 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
|
|||||||
parts[r>>8].tmp2 = (0xFFFF & (int)((parts[i].x - x) * 255.0f)) | (0xFFFF0000 & (int)((parts[i].y - y) * 16711680.0f));
|
parts[r>>8].tmp2 = (0xFFFF & (int)((parts[i].x - x) * 255.0f)) | (0xFFFF0000 & (int)((parts[i].y - y) * 16711680.0f));
|
||||||
kill_part(i);
|
kill_part(i);
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else if ((r&0xFF) == PT_INVIS)
|
case PT_INVIS:
|
||||||
{
|
{
|
||||||
float pressureResistance = 0.0f;
|
float pressureResistance = 0.0f;
|
||||||
if (parts[r>>8].tmp > 0)
|
if (parts[r>>8].tmp > 0)
|
||||||
@@ -2360,13 +2369,16 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
|
|||||||
part_change_type(i,x,y,PT_NEUT);
|
part_change_type(i,x,y,PT_NEUT);
|
||||||
parts[i].ctype = 0;
|
parts[i].ctype = 0;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if ((r&0xFF)==PT_BIZR || (r&0xFF)==PT_BIZRG || (r&0xFF)==PT_BIZRS)
|
case PT_BIZR:
|
||||||
{
|
case PT_BIZRG:
|
||||||
|
case PT_BIZRS:
|
||||||
part_change_type(i, x, y, PT_ELEC);
|
part_change_type(i, x, y, PT_ELEC);
|
||||||
parts[i].ctype = 0;
|
parts[i].ctype = 0;
|
||||||
}
|
break;
|
||||||
else if ((r&0xFF) == PT_H2 && !(parts[i].tmp&0x1))
|
case PT_H2:
|
||||||
|
if (!(parts[i].tmp&0x1))
|
||||||
{
|
{
|
||||||
part_change_type(i, x, y, PT_PROT);
|
part_change_type(i, x, y, PT_PROT);
|
||||||
parts[i].ctype = 0;
|
parts[i].ctype = 0;
|
||||||
@@ -2375,60 +2387,63 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
|
|||||||
create_part(r>>8, x, y, PT_ELEC);
|
create_part(r>>8, x, y, PT_ELEC);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if ((r&0xFF) == PT_GPMP)
|
break;
|
||||||
{
|
case PT_GPMP:
|
||||||
if (parts[r>>8].life == 0)
|
if (parts[r>>8].life == 0)
|
||||||
{
|
{
|
||||||
part_change_type(i, x, y, PT_GRVT);
|
part_change_type(i, x, y, PT_GRVT);
|
||||||
parts[i].tmp = parts[r>>8].temp - 273.15f;
|
parts[i].tmp = parts[r>>8].temp - 273.15f;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else if (parts[i].type == PT_NEUT)
|
case PT_NEUT:
|
||||||
{
|
|
||||||
if ((r&0xFF) == PT_GLAS || (r&0xFF) == PT_BGLA)
|
if ((r&0xFF) == PT_GLAS || (r&0xFF) == PT_BGLA)
|
||||||
if (rand() < RAND_MAX/10)
|
if (rand() < RAND_MAX/10)
|
||||||
create_cherenkov_photon(i);
|
create_cherenkov_photon(i);
|
||||||
}
|
break;
|
||||||
else if (parts[i].type == PT_ELEC)
|
case PT_ELEC:
|
||||||
{
|
|
||||||
if ((r&0xFF) == PT_GLOW)
|
if ((r&0xFF) == PT_GLOW)
|
||||||
{
|
{
|
||||||
part_change_type(i, x, y, PT_PHOT);
|
part_change_type(i, x, y, PT_PHOT);
|
||||||
parts[i].ctype = 0x3FFFFFFF;
|
parts[i].ctype = 0x3FFFFFFF;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else if (parts[i].type == PT_PROT)
|
case PT_PROT:
|
||||||
{
|
|
||||||
if ((r&0xFF) == PT_INVIS)
|
if ((r&0xFF) == PT_INVIS)
|
||||||
part_change_type(i, x, y, PT_NEUT);
|
part_change_type(i, x, y, PT_NEUT);
|
||||||
}
|
break;
|
||||||
else if ((parts[i].type == PT_BIZR || parts[i].type == PT_BIZRG))
|
case PT_BIZR:
|
||||||
{
|
case PT_BIZRG:
|
||||||
if ((r&0xFF) == PT_FILT)
|
if ((r&0xFF) == PT_FILT)
|
||||||
parts[i].ctype = Element_FILT::interactWavelengths(&parts[r>>8], parts[i].ctype);
|
parts[i].ctype = Element_FILT::interactWavelengths(&parts[r>>8], parts[i].ctype);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
//else e=1 , we are trying to swap the particles, return 0 no swap/move, 1 is still overlap/move, because the swap takes place later
|
//else e=1 , we are trying to swap the particles, return 0 no swap/move, 1 is still overlap/move, because the swap takes place later
|
||||||
|
|
||||||
if ((r&0xFF)==PT_VOID || (r&0xFF)==PT_PVOD) //this is where void eats particles
|
switch (r&0xFF)
|
||||||
{
|
{
|
||||||
|
case PT_VOID:
|
||||||
|
case PT_PVOD:
|
||||||
|
// this is where void eats particles
|
||||||
// void ctype already checked in eval_move
|
// void ctype already checked in eval_move
|
||||||
kill_part(i);
|
kill_part(i);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
case PT_BHOL:
|
||||||
else if ((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) //this is where blackhole eats particles
|
case PT_NBHL:
|
||||||
{
|
// this is where blackhole eats particles
|
||||||
if (!legacy_enable)
|
if (!legacy_enable)
|
||||||
{
|
{
|
||||||
parts[r>>8].temp = restrict_flt(parts[r>>8].temp+parts[i].temp/2, MIN_TEMP, MAX_TEMP);//3.0f;
|
parts[r>>8].temp = restrict_flt(parts[r>>8].temp+parts[i].temp/2, MIN_TEMP, MAX_TEMP);//3.0f;
|
||||||
}
|
}
|
||||||
kill_part(i);
|
kill_part(i);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
case PT_WHOL:
|
||||||
else if (((r&0xFF)==PT_WHOL || (r&0xFF)==PT_NWHL)) //whitehole eats anar
|
case PT_NWHL:
|
||||||
{
|
// whitehole eats anar
|
||||||
if (parts[i].type == PT_ANAR)
|
if (parts[i].type == PT_ANAR)
|
||||||
{
|
{
|
||||||
if (!legacy_enable)
|
if (!legacy_enable)
|
||||||
@@ -2438,9 +2453,8 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
|
|||||||
kill_part(i);
|
kill_part(i);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else if ((r&0xFF)==PT_DEUT)
|
case PT_DEUT:
|
||||||
{
|
|
||||||
if (parts[i].type == PT_ELEC)
|
if (parts[i].type == PT_ELEC)
|
||||||
{
|
{
|
||||||
if(parts[r>>8].life < 6000)
|
if(parts[r>>8].life < 6000)
|
||||||
@@ -2449,34 +2463,35 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
|
|||||||
kill_part(i);
|
kill_part(i);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else if (((r&0xFF)==PT_VIBR || (r&0xFF)==PT_BVBR))
|
case PT_VIBR:
|
||||||
{
|
case PT_BVBR:
|
||||||
if ((elements[parts[i].type].Properties & TYPE_ENERGY))
|
if ((elements[parts[i].type].Properties & TYPE_ENERGY))
|
||||||
{
|
{
|
||||||
parts[r>>8].tmp += 20;
|
parts[r>>8].tmp += 20;
|
||||||
kill_part(i);
|
kill_part(i);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parts[i].type == PT_NEUT)
|
switch (parts[i].type)
|
||||||
{
|
{
|
||||||
|
case PT_NEUT:
|
||||||
if (elements[r&0xFF].Properties & PROP_NEUTABSORB)
|
if (elements[r&0xFF].Properties & PROP_NEUTABSORB)
|
||||||
{
|
{
|
||||||
kill_part(i);
|
kill_part(i);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else if (parts[i].type == PT_CNCT)
|
case PT_CNCT:
|
||||||
{
|
|
||||||
if (y < ny && (pmap[y+1][x]&0xFF) == PT_CNCT) //check below CNCT for another CNCT
|
if (y < ny && (pmap[y+1][x]&0xFF) == PT_CNCT) //check below CNCT for another CNCT
|
||||||
return 0;
|
return 0;
|
||||||
}
|
break;
|
||||||
else if(parts[i].type == PT_GBMB)
|
case PT_GBMB:
|
||||||
{
|
|
||||||
if (parts[i].life > 0)
|
if (parts[i].life > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((bmap[y/CELL][x/CELL]==WL_EHOLE && !emap[y/CELL][x/CELL]) && !(bmap[ny/CELL][nx/CELL]==WL_EHOLE && !emap[ny/CELL][nx/CELL]))
|
if ((bmap[y/CELL][x/CELL]==WL_EHOLE && !emap[y/CELL][x/CELL]) && !(bmap[ny/CELL][nx/CELL]==WL_EHOLE && !emap[ny/CELL][nx/CELL]))
|
||||||
@@ -3082,11 +3097,6 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
|
|||||||
case PT_ACID: case PT_CAUS:
|
case PT_ACID: case PT_CAUS:
|
||||||
parts[i].life = 75;
|
parts[i].life = 75;
|
||||||
break;
|
break;
|
||||||
/*Testing
|
|
||||||
case PT_WOOD:
|
|
||||||
parts[i].life = 150;
|
|
||||||
break;
|
|
||||||
End Testing*/
|
|
||||||
case PT_WARP:
|
case PT_WARP:
|
||||||
parts[i].life = rand()%95+70;
|
parts[i].life = rand()%95+70;
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user