mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-16 21:34:01 +02:00
replace some if-else with switch statements, code formatting, closes #444
This commit is contained in:
@@ -2182,19 +2182,19 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr)
|
||||
if (pt>=PT_NUM || (r&0xFF)>=PT_NUM)
|
||||
return 0;
|
||||
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)
|
||||
result = (parts[r>>8].life > 5)? 2 : 0;
|
||||
}
|
||||
else if ((r&0xFF) == PT_GPMP)
|
||||
{
|
||||
break;
|
||||
case PT_GPMP:
|
||||
if (pt == PT_PHOT)
|
||||
result = (parts[r>>8].life < 10) ? 2 : 0;
|
||||
}
|
||||
else if ((r&0xFF) == PT_INVIS)
|
||||
break;
|
||||
case PT_INVIS:
|
||||
{
|
||||
float pressureResistance = 0.0f;
|
||||
if (parts[r>>8].tmp > 0)
|
||||
@@ -2206,9 +2206,9 @@ int Simulation::eval_move(int pt, int nx, int ny, unsigned *rr)
|
||||
result = 2;
|
||||
else
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
else if ((r&0xFF) == PT_PVOD)
|
||||
{
|
||||
case PT_PVOD:
|
||||
if (parts[r>>8].life == 10)
|
||||
{
|
||||
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;
|
||||
}
|
||||
else result = 0;
|
||||
}
|
||||
else if ((r&0xFF) == PT_VOID)
|
||||
{
|
||||
break;
|
||||
case PT_VOID:
|
||||
if (!parts[r>>8].ctype || (parts[r>>8].ctype==pt)!=(parts[r>>8].tmp&1))
|
||||
result = 1;
|
||||
else
|
||||
result = 0;
|
||||
}
|
||||
else if (pt == PT_TRON && (r&0xFF) == PT_SWCH)
|
||||
break;
|
||||
case PT_SWCH:
|
||||
if (pt == PT_TRON)
|
||||
{
|
||||
if (parts[r>>8].life >= 10)
|
||||
return 2;
|
||||
else
|
||||
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])
|
||||
{
|
||||
@@ -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 (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)
|
||||
{
|
||||
parts[r>>8].life = 120;
|
||||
create_gain_photon(i);
|
||||
}
|
||||
}
|
||||
else if ((r&0xFF) == PT_FILT)
|
||||
break;
|
||||
case PT_FILT:
|
||||
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))
|
||||
{
|
||||
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));
|
||||
kill_part(i);
|
||||
}
|
||||
}
|
||||
else if ((r&0xFF) == PT_INVIS)
|
||||
break;
|
||||
case PT_INVIS:
|
||||
{
|
||||
float pressureResistance = 0.0f;
|
||||
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);
|
||||
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);
|
||||
parts[i].ctype = 0;
|
||||
}
|
||||
else if ((r&0xFF) == PT_H2 && !(parts[i].tmp&0x1))
|
||||
break;
|
||||
case PT_H2:
|
||||
if (!(parts[i].tmp&0x1))
|
||||
{
|
||||
part_change_type(i, x, y, PT_PROT);
|
||||
parts[i].ctype = 0;
|
||||
@@ -2375,72 +2387,74 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
|
||||
create_part(r>>8, x, y, PT_ELEC);
|
||||
return 1;
|
||||
}
|
||||
else if ((r&0xFF) == PT_GPMP)
|
||||
{
|
||||
break;
|
||||
case PT_GPMP:
|
||||
if (parts[r>>8].life == 0)
|
||||
{
|
||||
part_change_type(i, x, y, PT_GRVT);
|
||||
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 (rand() < RAND_MAX/10)
|
||||
create_cherenkov_photon(i);
|
||||
}
|
||||
else if (parts[i].type == PT_ELEC)
|
||||
{
|
||||
break;
|
||||
case PT_ELEC:
|
||||
if ((r&0xFF) == PT_GLOW)
|
||||
{
|
||||
part_change_type(i, x, y, PT_PHOT);
|
||||
parts[i].ctype = 0x3FFFFFFF;
|
||||
}
|
||||
}
|
||||
else if (parts[i].type == PT_PROT)
|
||||
{
|
||||
break;
|
||||
case PT_PROT:
|
||||
if ((r&0xFF) == PT_INVIS)
|
||||
part_change_type(i, x, y, PT_NEUT);
|
||||
}
|
||||
else if ((parts[i].type == PT_BIZR || parts[i].type == PT_BIZRG))
|
||||
{
|
||||
break;
|
||||
case PT_BIZR:
|
||||
case PT_BIZRG:
|
||||
if ((r&0xFF) == PT_FILT)
|
||||
parts[i].ctype = Element_FILT::interactWavelengths(&parts[r>>8], parts[i].ctype);
|
||||
break;
|
||||
}
|
||||
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
|
||||
|
||||
if ((r&0xFF)==PT_VOID || (r&0xFF)==PT_PVOD) //this is where void eats particles
|
||||
switch (r&0xFF)
|
||||
{
|
||||
//void ctype already checked in eval_move
|
||||
case PT_VOID:
|
||||
case PT_PVOD:
|
||||
// this is where void eats particles
|
||||
// void ctype already checked in eval_move
|
||||
kill_part(i);
|
||||
return 0;
|
||||
}
|
||||
else if ((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) //this is where blackhole eats particles
|
||||
{
|
||||
case PT_BHOL:
|
||||
case PT_NBHL:
|
||||
// this is where blackhole eats particles
|
||||
if (!legacy_enable)
|
||||
{
|
||||
parts[r>>8].temp = restrict_flt(parts[r>>8].temp+parts[i].temp/2, MIN_TEMP, MAX_TEMP);//3.0f;
|
||||
}
|
||||
kill_part(i);
|
||||
return 0;
|
||||
}
|
||||
else if (((r&0xFF)==PT_WHOL || (r&0xFF)==PT_NWHL)) //whitehole eats anar
|
||||
{
|
||||
case PT_WHOL:
|
||||
case PT_NWHL:
|
||||
// whitehole eats anar
|
||||
if (parts[i].type == PT_ANAR)
|
||||
{
|
||||
if (!legacy_enable)
|
||||
{
|
||||
parts[r>>8].temp = restrict_flt(parts[r>>8].temp- (MAX_TEMP-parts[i].temp)/2, MIN_TEMP, MAX_TEMP);
|
||||
parts[r>>8].temp = restrict_flt(parts[r>>8].temp - (MAX_TEMP-parts[i].temp)/2, MIN_TEMP, MAX_TEMP);
|
||||
}
|
||||
kill_part(i);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if ((r&0xFF)==PT_DEUT)
|
||||
{
|
||||
break;
|
||||
case PT_DEUT:
|
||||
if (parts[i].type == PT_ELEC)
|
||||
{
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (((r&0xFF)==PT_VIBR || (r&0xFF)==PT_BVBR))
|
||||
{
|
||||
break;
|
||||
case PT_VIBR:
|
||||
case PT_BVBR:
|
||||
if ((elements[parts[i].type].Properties & TYPE_ENERGY))
|
||||
{
|
||||
parts[r>>8].tmp += 20;
|
||||
kill_part(i);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (parts[i].type == PT_NEUT)
|
||||
switch (parts[i].type)
|
||||
{
|
||||
if (elements[r & 0xFF].Properties & PROP_NEUTABSORB)
|
||||
case PT_NEUT:
|
||||
if (elements[r&0xFF].Properties & PROP_NEUTABSORB)
|
||||
{
|
||||
kill_part(i);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (parts[i].type == PT_CNCT)
|
||||
{
|
||||
if (y<ny && (pmap[y+1][x]&0xFF) == PT_CNCT) //check below CNCT for another CNCT
|
||||
break;
|
||||
case PT_CNCT:
|
||||
if (y < ny && (pmap[y+1][x]&0xFF) == PT_CNCT) //check below CNCT for another CNCT
|
||||
return 0;
|
||||
}
|
||||
else if(parts[i].type == PT_GBMB)
|
||||
{
|
||||
if (parts[i].life>0)
|
||||
break;
|
||||
case PT_GBMB:
|
||||
if (parts[i].life > 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]))
|
||||
@@ -3082,11 +3097,6 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
|
||||
case PT_ACID: case PT_CAUS:
|
||||
parts[i].life = 75;
|
||||
break;
|
||||
/*Testing
|
||||
case PT_WOOD:
|
||||
parts[i].life = 150;
|
||||
break;
|
||||
End Testing*/
|
||||
case PT_WARP:
|
||||
parts[i].life = rand()%95+70;
|
||||
break;
|
||||
@@ -3095,7 +3105,7 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
|
||||
parts[i].tmp = 50;
|
||||
break;
|
||||
case PT_LIFE:
|
||||
if (v<NGOL)
|
||||
if (v < NGOL)
|
||||
{
|
||||
parts[i].tmp = grule[v+1][9] - 1;
|
||||
parts[i].ctype = v;
|
||||
@@ -3219,7 +3229,7 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
|
||||
}
|
||||
case PT_STKM2:
|
||||
{
|
||||
if (player2.spwn==0)
|
||||
if (player2.spwn == 0)
|
||||
{
|
||||
parts[i].life = 100;
|
||||
Element_STKM::STKM_init_legs(this, &player2, i);
|
||||
@@ -3228,7 +3238,7 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
|
||||
}
|
||||
else
|
||||
{
|
||||
parts[i].type=0;
|
||||
parts[i].type = 0;
|
||||
return -1;
|
||||
}
|
||||
int spawnID = create_part(-3, x, y, PT_SPAWN2);
|
||||
@@ -3240,7 +3250,7 @@ int Simulation::create_part(int p, int x, int y, int t, int v)
|
||||
{
|
||||
unsigned char fcount = 0;
|
||||
while (fcount < MAX_FIGHTERS && fcount < (fighcount+1) && fighters[fcount].spwn==1) fcount++;
|
||||
if (fcount < MAX_FIGHTERS && fighters[fcount].spwn==0)
|
||||
if (fcount < MAX_FIGHTERS && fighters[fcount].spwn == 0)
|
||||
{
|
||||
parts[i].life = 100;
|
||||
parts[i].tmp = fcount;
|
||||
|
Reference in New Issue
Block a user