1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-30 16:38:29 +02:00

Fix nested if-statement chains relating to entities in Entity.cpp

These would be of the form
if (cond1) { if (cond2) { if (cond3) { thing; } } }
which is really annoying to read and could've been written as
if (cond1 && cond2 && cond3) { thing; }
so that's what I'm fixing here.

There will be another commit later that fixes this but in places related
to blocks.
This commit is contained in:
Misa 2020-04-03 14:48:27 -07:00 committed by Ethan Lee
parent e40a4c3948
commit 2f3eeccdf0

View File

@ -4106,11 +4106,8 @@ float entityclass::hplatformat()
//Returns first entity of horizontal platform at (px, py), -1000 otherwise. //Returns first entity of horizontal platform at (px, py), -1000 otherwise.
for (size_t i = 0; i < entities.size(); i++) for (size_t i = 0; i < entities.size(); i++)
{ {
if (entities[i].rule == 2) if (entities[i].rule == 2 && entities[i].behave >= 2
{ && entities[i].xp == px && entities[i].yp == py)
if (entities[i].behave >= 2)
{
if (entities[i].xp == px && entities[i].yp == py)
{ {
if (entities[i].behave == 8) //threadmill! if (entities[i].behave == 8) //threadmill!
{ {
@ -4126,8 +4123,6 @@ float entityclass::hplatformat()
} }
} }
} }
}
}
return -1000; return -1000;
} }
@ -4161,9 +4156,8 @@ bool entityclass::entityhlinecollide( int t, int l )
bool entityclass::entityvlinecollide( int t, int l ) bool entityclass::entityvlinecollide( int t, int l )
{ {
//Returns true is entity t collided with the vertical line l. //Returns true is entity t collided with the vertical line l.
if(entities[t].yp + entities[t].cy+entities[t].h>=entities[l].yp) if(entities[t].yp + entities[t].cy+entities[t].h>=entities[l].yp
{ && entities[t].yp + entities[t].cy<=entities[l].yp+entities[l].h)
if(entities[t].yp + entities[t].cy<=entities[l].yp+entities[l].h)
{ {
linetemp = 0; linetemp = 0;
@ -4175,14 +4169,13 @@ bool entityclass::entityvlinecollide( int t, int l )
if (linetemp > -4 && linetemp < 4) return true; if (linetemp > -4 && linetemp < 4) return true;
return false; return false;
} }
}
return false; return false;
} }
bool entityclass::entitywarphlinecollide(int t, int l) { bool entityclass::entitywarphlinecollide(int t, int l) {
//Returns true is entity t collided with the horizontal line l. //Returns true is entity t collided with the horizontal line l.
if(entities[t].xp + entities[t].cx+entities[t].w>=entities[l].xp){ if(entities[t].xp + entities[t].cx+entities[t].w>=entities[l].xp
if(entities[t].xp + entities[t].cx<=entities[l].xp+entities[l].w){ &&entities[t].xp + entities[t].cx<=entities[l].xp+entities[l].w){
linetemp = 0; linetemp = 0;
if (entities[l].yp < 120) { if (entities[l].yp < 120) {
//Top line //Top line
@ -4208,14 +4201,13 @@ bool entityclass::entitywarphlinecollide(int t, int l) {
return false; return false;
} }
} }
}
return false; return false;
} }
bool entityclass::entitywarpvlinecollide(int t, int l) { bool entityclass::entitywarpvlinecollide(int t, int l) {
//Returns true is entity t collided with the vertical warp line l. //Returns true is entity t collided with the vertical warp line l.
if(entities[t].yp + entities[t].cy+entities[t].h>=entities[l].yp){ if(entities[t].yp + entities[t].cy+entities[t].h>=entities[l].yp
if (entities[t].yp + entities[t].cy <= entities[l].yp + entities[l].h) { && entities[t].yp + entities[t].cy <= entities[l].yp + entities[l].h) {
linetemp = 0; linetemp = 0;
if (entities[l].xp < 160) { if (entities[l].xp < 160) {
//Left hand line //Left hand line
@ -4237,7 +4229,6 @@ bool entityclass::entitywarpvlinecollide(int t, int l) {
return false; return false;
} }
} }
}
return false; return false;
} }
@ -4566,24 +4557,20 @@ void entityclass::customwarplinecheck(int i) {
//We test entity to entity //We test entity to entity
for (int j = 0; j < (int) entities.size(); j++) { for (int j = 0; j < (int) entities.size(); j++) {
if (i != j) {//Active if (i != j) {//Active
if (entities[i].rule == 0 && entities[j].rule == 5) { //Player vs vertical line! if (entities[i].rule == 0 && entities[j].rule == 5 //Player vs vertical line!
if (entities[j].type == 51 || entities[j].type == 52) { && (entities[j].type == 51 || entities[j].type == 52)
if (entitywarpvlinecollide(i, j)) { && entitywarpvlinecollide(i, j)) {
customwarpmodevon = true; customwarpmodevon = true;
} }
}
}
if (entities[i].rule == 0 && entities[j].rule == 7){ //Player vs horizontal WARP line if (entities[i].rule == 0 && entities[j].rule == 7 //Player vs horizontal WARP line
if (entities[j].type == 53 || entities[j].type == 54) { && (entities[j].type == 53 || entities[j].type == 54)
if (entitywarphlinecollide(i, j)) { && entitywarphlinecollide(i, j)) {
customwarpmodehon = true; customwarpmodehon = true;
} }
} }
} }
} }
}
}
void entityclass::entitycollisioncheck() void entityclass::entitycollisioncheck()
{ {