1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-31 22:19:44 +01:00

Use explicit INBOUNDS_VEC() instead of checking sentinel -1

It's better to do INBOUNDS_VEC(i, obj.entities) instead of 'i > -1'.

'i > -1' is used in cases like obj.getplayer(), which COULD return a
sentinel value of -1 and so correct code will have to check that value.
However, I am now of the opinion that INBOUNDS_VEC() should be used and
isn't unnecessary.

Consider the case of the face() script command: it's not enough to check
i > -1, you should read the routine carefully. Because if you look
closely, you'll see that it's not guaranteed that 'i' will be initialized
at all in that command. Indeed, if you call face() with invalid
arguments, it won't be. And so, 'i' could be something like 215, and
that would index out-of-bounds, and that wouldn't be good. Therefore,
it's better to have the full bounds check instead of checking only one
bounds. Many commands are like this, after some searching I can also
name position(), changemood(), changetile(), changegravity(), etc.

It also makes the code more explicit. Now you don't have to wonder what
-1 means or why it's being checked, you can just read the 'INBOUNDS' and
go "oh, that checks if it's actually inbounds or not".
This commit is contained in:
Misa 2020-09-09 04:15:14 -07:00 committed by Ethan Lee
parent b925352864
commit b34be3f1ac
7 changed files with 236 additions and 235 deletions

View file

@ -2093,11 +2093,11 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
// Face the player
// FIXME: Duplicated from updateentities!
int j = getplayer();
if (j > -1 && entities[j].xp > entity.xp + 5)
if (INBOUNDS_VEC(j, entities) && entities[j].xp > entity.xp + 5)
{
entity.dir = 1;
}
else if (j > -1 && entities[j].xp < entity.xp - 5)
else if (INBOUNDS_VEC(j, entities) && entities[j].xp < entity.xp - 5)
{
entity.dir = 0;
}
@ -2422,7 +2422,7 @@ bool entityclass::updateentities( int i )
{
int player = getplayer();
//first, y position
if (player > -1 && entities[player].yp > 14 * 8)
if (INBOUNDS_VEC(player, entities) && entities[player].yp > 14 * 8)
{
entities[i].tile = 120;
entities[i].yp = (28*8)-62;
@ -2435,7 +2435,7 @@ bool entityclass::updateentities( int i )
entities[i].oldyp = 24;
}
//now, x position
if (player > -1 && entities[player].xp > 20 * 8)
if (INBOUNDS_VEC(player, entities) && entities[player].xp > 20 * 8)
{
//approach from the left
entities[i].xp = -64;
@ -2647,7 +2647,7 @@ bool entityclass::updateentities( int i )
game.saverx = game.roomx;
game.savery = game.roomy;
int player = getplayer();
if (player > -1)
if (INBOUNDS_VEC(player, entities))
{
game.savedir = entities[player].dir;
}
@ -2680,11 +2680,11 @@ bool entityclass::updateentities( int i )
temp = getplayer();
if (game.gravitycontrol == 0)
{
if (temp > -1 && entities[temp].vy < 3) entities[temp].vy = 3;
if (INBOUNDS_VEC(temp, entities) && entities[temp].vy < 3) entities[temp].vy = 3;
}
else
{
if (temp > -1 && entities[temp].vy > -3) entities[temp].vy = -3;
if (INBOUNDS_VEC(temp, entities) && entities[temp].vy > -3) entities[temp].vy = -3;
}
}
else if (entities[i].state == 2)
@ -2737,20 +2737,20 @@ bool entityclass::updateentities( int i )
if (entities[k].rule == 7) entities[k].tile = 6;
//Stay close to the hero!
int j = getplayer();
if (j > -1 && entities[j].xp > entities[i].xp + 5)
if (INBOUNDS_VEC(j, entities) && entities[j].xp > entities[i].xp + 5)
{
entities[i].dir = 1;
}
else if (j > -1 && entities[j].xp < entities[i].xp - 5)
else if (INBOUNDS_VEC(j, entities) && entities[j].xp < entities[i].xp - 5)
{
entities[i].dir = 0;
}
if (j > -1 && entities[j].xp > entities[i].xp + 45)
if (INBOUNDS_VEC(j, entities) && entities[j].xp > entities[i].xp + 45)
{
entities[i].ax = 3;
}
else if (j > -1 && entities[j].xp < entities[i].xp - 45)
else if (INBOUNDS_VEC(j, entities) && entities[j].xp < entities[i].xp - 45)
{
entities[i].ax = -3;
}
@ -2768,20 +2768,20 @@ bool entityclass::updateentities( int i )
{
//Basic rules, don't change expression
int j = getplayer();
if (j > -1 && entities[j].xp > entities[i].xp + 5)
if (INBOUNDS_VEC(j, entities) && entities[j].xp > entities[i].xp + 5)
{
entities[i].dir = 1;
}
else if (j > -1 && entities[j].xp < entities[i].xp - 5)
else if (INBOUNDS_VEC(j, entities) && entities[j].xp < entities[i].xp - 5)
{
entities[i].dir = 0;
}
if (j > -1 && entities[j].xp > entities[i].xp + 45)
if (INBOUNDS_VEC(j, entities) && entities[j].xp > entities[i].xp + 45)
{
entities[i].ax = 3;
}
else if (j > -1 && entities[j].xp < entities[i].xp - 45)
else if (INBOUNDS_VEC(j, entities) && entities[j].xp < entities[i].xp - 45)
{
entities[i].ax = -3;
}
@ -2791,20 +2791,20 @@ bool entityclass::updateentities( int i )
//Everything from 10 on is for cutscenes
//Basic rules, don't change expression
int j = getplayer();
if (j > -1 && entities[j].xp > entities[i].xp + 5)
if (INBOUNDS_VEC(j, entities) && entities[j].xp > entities[i].xp + 5)
{
entities[i].dir = 1;
}
else if (j > -1 && entities[j].xp < entities[i].xp - 5)
else if (INBOUNDS_VEC(j, entities) && entities[j].xp < entities[i].xp - 5)
{
entities[i].dir = 0;
}
if (j > -1 && entities[j].xp > entities[i].xp + 45)
if (INBOUNDS_VEC(j, entities) && entities[j].xp > entities[i].xp + 45)
{
entities[i].ax = 3;
}
else if (j > -1 && entities[j].xp < entities[i].xp - 45)
else if (INBOUNDS_VEC(j, entities) && entities[j].xp < entities[i].xp - 45)
{
entities[i].ax = -3;
}
@ -2949,11 +2949,11 @@ bool entityclass::updateentities( int i )
//Stand still and face the player
//FIXME: Duplicated in createentity!
int j = getplayer();
if (j > -1 && entities[j].xp > entities[i].xp + 5)
if (INBOUNDS_VEC(j, entities) && entities[j].xp > entities[i].xp + 5)
{
entities[i].dir = 1;
}
else if (j > -1 && entities[j].xp < entities[i].xp - 5)
else if (INBOUNDS_VEC(j, entities) && entities[j].xp < entities[i].xp - 5)
{
entities[i].dir = 0;
}
@ -3065,7 +3065,7 @@ bool entityclass::updateentities( int i )
{
//follow player, but only if he's on the floor!
int j = getplayer();
if(j > -1 && entities[j].onground>0)
if(INBOUNDS_VEC(j, entities) && entities[j].onground>0)
{
if (entities[j].xp > entities[i].xp + 5)
{
@ -3091,11 +3091,11 @@ bool entityclass::updateentities( int i )
}
else
{
if (j > -1 && entities[j].xp > entities[i].xp + 5)
if (INBOUNDS_VEC(j, entities) && entities[j].xp > entities[i].xp + 5)
{
entities[i].dir = 1;
}
else if (j > -1 && entities[j].xp < entities[i].xp - 5)
else if (INBOUNDS_VEC(j, entities) && entities[j].xp < entities[i].xp - 5)
{
entities[i].dir = 0;
}
@ -3156,7 +3156,7 @@ bool entityclass::updateentities( int i )
case 51: //Vertical warp line
if (entities[i].state == 2){
int j=getplayer();
if(j > -1 && entities[j].xp<=307){
if(INBOUNDS_VEC(j, entities) && entities[j].xp<=307){
customwarpmodevon=false;
entities[i].state = 0;
}
@ -3171,7 +3171,7 @@ bool entityclass::updateentities( int i )
case 52: //Vertical warp line
if (entities[i].state == 2){
int j=getplayer();
if(j > -1 && entities[j].xp<=307){
if(INBOUNDS_VEC(j, entities) && entities[j].xp<=307){
customwarpmodevon=false;
entities[i].state = 0;
}
@ -3213,11 +3213,11 @@ bool entityclass::updateentities( int i )
{
//Basic rules, don't change expression
int j = getplayer();
if (j > -1 && entities[j].xp > entities[i].xp + 5)
if (INBOUNDS_VEC(j, entities) && entities[j].xp > entities[i].xp + 5)
{
entities[i].dir = 1;
}
else if (j > -1 && entities[j].xp < entities[i].xp - 5)
else if (INBOUNDS_VEC(j, entities) && entities[j].xp < entities[i].xp - 5)
{
entities[i].dir = 0;
}
@ -3284,7 +3284,7 @@ bool entityclass::updateentities( int i )
game.saverx = game.roomx;
game.savery = game.roomy;
int player = getplayer();
if (player > -1)
if (INBOUNDS_VEC(player, entities))
{
game.savedir = entities[player].dir;
}
@ -4632,7 +4632,7 @@ void entityclass::entitycollisioncheck()
// WARNING: If updating this code, don't forget to update Map.cpp mapclass::twoframedelayfix()
activetrigger = -1;
int block_idx = -1;
if (checktrigger(&block_idx) > -1 && block_idx > -1)
if (INBOUNDS_VEC(checktrigger(&block_idx), entities) && INBOUNDS_VEC(block_idx, blocks))
{
// Load the block's script if its gamestate is out of range
if (blocks[block_idx].script != "" && (activetrigger < 300 || activetrigger > 336))

View file

@ -397,7 +397,7 @@ void Game::lifesequence()
if (lifeseq > 0)
{
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].invis = false;
if (lifeseq == 2) obj.entities[i].invis = true;
@ -407,7 +407,7 @@ void Game::lifesequence()
if (lifeseq > 5) gravitycontrol = savegc;
lifeseq--;
if (i > -1 && lifeseq <= 0)
if (INBOUNDS_VEC(i, obj.entities) && lifeseq <= 0)
{
obj.entities[i].invis = false;
}
@ -862,7 +862,7 @@ void Game::updatestate()
{
//leaving the naughty corner
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[obj.getplayer()].tile = 0;
}
@ -873,7 +873,7 @@ void Game::updatestate()
{
//entering the naughty corner
int i = obj.getplayer();
if(i > -1 && obj.entities[i].tile == 0)
if(INBOUNDS_VEC(i, obj.entities) && obj.entities[i].tile == 0)
{
obj.entities[i].tile = 144;
music.playef(2);
@ -1470,12 +1470,12 @@ void Game::updatestate()
int i = obj.getplayer();
hascontrol = false;
if (i > -1 && obj.entities[i].onroof > 0 && gravitycontrol == 1)
if (INBOUNDS_VEC(i, obj.entities) && obj.entities[i].onroof > 0 && gravitycontrol == 1)
{
gravitycontrol = 0;
music.playef(1);
}
if (i > -1 && obj.entities[i].onground > 0)
if (INBOUNDS_VEC(i, obj.entities) && obj.entities[i].onground > 0)
{
state++;
}
@ -1487,7 +1487,7 @@ void Game::updatestate()
companion = 6;
int i = obj.getcompanion();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 0;
obj.entities[i].state = 1;
@ -1516,7 +1516,7 @@ void Game::updatestate()
music.playef(2);
graphics.textboxactive();
int i = obj.getcompanion();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 54;
obj.entities[i].state = 0;
@ -1534,7 +1534,7 @@ void Game::updatestate()
{
int i = obj.getcompanion();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 0;
obj.entities[i].state = 1;
@ -1594,12 +1594,12 @@ void Game::updatestate()
int i = obj.getplayer();
hascontrol = false;
if (i > -1 && obj.entities[i].onground > 0 && gravitycontrol == 0)
if (INBOUNDS_VEC(i, obj.entities) && obj.entities[i].onground > 0 && gravitycontrol == 0)
{
gravitycontrol = 1;
music.playef(1);
}
if (i > -1 && obj.entities[i].onroof > 0)
if (INBOUNDS_VEC(i, obj.entities) && obj.entities[i].onroof > 0)
{
state++;
}
@ -1610,7 +1610,7 @@ void Game::updatestate()
{
companion = 7;
int i = obj.getcompanion();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 6;
obj.entities[i].state = 1;
@ -1631,7 +1631,7 @@ void Game::updatestate()
state++;
music.playef(2);
graphics.textboxactive();
int i = obj.getcompanion(); if (i > -1) { /*obj.entities[i].tile = 66; obj.entities[i].state = 0;*/ }
int i = obj.getcompanion(); if (INBOUNDS_VEC(i, obj.entities)) { /*obj.entities[i].tile = 66; obj.entities[i].state = 0;*/ }
break;
}
case 126:
@ -1655,7 +1655,7 @@ void Game::updatestate()
music.playef(14);
graphics.textboxactive();
int i = obj.getcompanion();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 6;
obj.entities[i].state = 1;
@ -1976,13 +1976,13 @@ void Game::updatestate()
statedelay = 5;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].colour = 0;
obj.entities[i].invis = false;
int j = obj.getteleporter();
if (j > -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[i].xp = obj.entities[j].xp+44;
obj.entities[i].yp = obj.entities[j].yp+44;
@ -1996,7 +1996,7 @@ void Game::updatestate()
}
i = obj.getteleporter();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 1;
obj.entities[i].colour = 101;
@ -2007,7 +2007,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 10;
}
@ -2017,7 +2017,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
//obj.entities[i].xp += 10;
}
@ -2027,7 +2027,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 8;
}
@ -2037,7 +2037,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 6;
}
@ -2047,7 +2047,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
//obj.entities[i].xp += 4;
}
@ -2057,7 +2057,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 2;
}
@ -2068,7 +2068,7 @@ void Game::updatestate()
state++;
statedelay = 15;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 1;
}
@ -2169,20 +2169,20 @@ void Game::updatestate()
}
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].colour = 0;
obj.entities[i].invis = true;
}
i = obj.getcompanion();
if(i>-1)
if(INBOUNDS_VEC(i, obj.entities))
{
obj.removeentity(i);
}
i = obj.getteleporter();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 1;
obj.entities[i].colour = 100;
@ -3169,7 +3169,7 @@ void Game::updatestate()
{
//Activating a teleporter (long version for level complete)
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].colour = 102;
}
@ -3211,7 +3211,7 @@ void Game::updatestate()
screenshake = 0;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].colour = 0;
obj.entities[i].invis = true;
@ -3304,14 +3304,14 @@ void Game::updatestate()
//state = 3040; //Lab
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].colour = 0;
obj.entities[i].invis = true;
}
i = obj.getteleporter();
if(i>-1)
if(INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 1;
obj.entities[i].colour = 100;
@ -3348,9 +3348,9 @@ void Game::updatestate()
int i = obj.getplayer();
int j = obj.getteleporter();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
if (j != -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[i].xp = obj.entities[j].xp+44;
obj.entities[i].yp = obj.entities[j].yp+44;
@ -3374,7 +3374,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 10;
}
@ -3384,7 +3384,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 10;
}
@ -3394,7 +3394,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 8;
}
@ -3404,7 +3404,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 6;
}
@ -3414,7 +3414,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 3;
}
@ -3425,7 +3425,7 @@ void Game::updatestate()
state++;
statedelay = 15;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 1;
}
@ -3442,7 +3442,7 @@ void Game::updatestate()
}
int i = obj.getteleporter();
activetele = true;
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
teleblock.x = obj.entities[i].xp - 32;
teleblock.y = obj.entities[i].yp - 32;
@ -3479,9 +3479,9 @@ void Game::updatestate()
int i = obj.getplayer();
int j = obj.getteleporter();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
if (j != -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[i].xp = obj.entities[j].xp+44;
obj.entities[i].yp = obj.entities[j].yp+44;
@ -3505,7 +3505,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 12;
}
@ -3515,7 +3515,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 12;
}
@ -3525,7 +3525,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 10;
}
@ -3535,7 +3535,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 8;
}
@ -3545,7 +3545,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 5;
}
@ -3556,7 +3556,7 @@ void Game::updatestate()
state++;
statedelay = 15;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 2;
}
@ -3592,9 +3592,9 @@ void Game::updatestate()
int i = obj.getplayer();
int j = obj.getteleporter();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
if (j != -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[i].xp = obj.entities[j].xp+44;
obj.entities[i].yp = obj.entities[j].yp+44;
@ -3618,7 +3618,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp -= 12;
}
@ -3628,7 +3628,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp -= 12;
}
@ -3638,7 +3638,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp -= 10;
}
@ -3648,7 +3648,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp -= 8;
}
@ -3658,7 +3658,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp -= 5;
}
@ -3669,7 +3669,7 @@ void Game::updatestate()
state++;
statedelay = 15;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp -= 2;
}
@ -3705,9 +3705,9 @@ void Game::updatestate()
int i = obj.getplayer();
int j = obj.getteleporter();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
if (j != -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[i].xp = obj.entities[j].xp+44;
obj.entities[i].yp = obj.entities[j].yp+44;
@ -3731,7 +3731,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 12;
obj.entities[i].yp -= 15;
@ -3742,7 +3742,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 12;
obj.entities[i].yp -= 10;
@ -3753,7 +3753,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 12;
obj.entities[i].yp -= 10;
@ -3764,7 +3764,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 8;
obj.entities[i].yp -= 8;
@ -3775,7 +3775,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 6;
obj.entities[i].yp -= 8;
@ -3787,7 +3787,7 @@ void Game::updatestate()
state++;
statedelay = 15;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 3;
}
@ -3823,9 +3823,9 @@ void Game::updatestate()
int i = obj.getplayer();
int j = obj.getteleporter();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
if (j != -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[i].xp = obj.entities[j].xp+44;
obj.entities[i].yp = obj.entities[j].yp+44;
@ -3849,7 +3849,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 4;
obj.entities[i].yp -= 15;
@ -3860,7 +3860,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 4;
obj.entities[i].yp -= 10;
@ -3871,7 +3871,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 4;
obj.entities[i].yp -= 10;
@ -3882,7 +3882,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 4;
obj.entities[i].yp -= 8;
@ -3893,7 +3893,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 2;
obj.entities[i].yp -= 8;
@ -3905,7 +3905,7 @@ void Game::updatestate()
state++;
statedelay = 15;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 1;
}
@ -3941,9 +3941,9 @@ void Game::updatestate()
int i = obj.getplayer();
int j = obj.getteleporter();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
if (j != -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[i].xp = obj.entities[j].xp+44;
obj.entities[i].yp = obj.entities[j].yp+44;
@ -3967,7 +3967,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp -= 28;
obj.entities[i].yp -= 8;
@ -3978,7 +3978,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp -= 28;
obj.entities[i].yp -= 8;
@ -3989,7 +3989,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp -= 25;
}
@ -3999,7 +3999,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp -= 25;
}
@ -4009,7 +4009,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp -= 20;
}
@ -4020,7 +4020,7 @@ void Game::updatestate()
state++;
statedelay = 15;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp -= 16;
}
@ -4057,9 +4057,9 @@ void Game::updatestate()
int i = obj.getplayer();
int j = obj.getteleporter();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
if (j != -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[i].xp = obj.entities[j].xp+44;
obj.entities[i].yp = obj.entities[j].yp+44;
@ -4083,7 +4083,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 10;
}
@ -4093,7 +4093,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 10;
}
@ -4103,7 +4103,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 8;
}
@ -4113,7 +4113,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 6;
}
@ -4123,7 +4123,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 3;
}
@ -4134,7 +4134,7 @@ void Game::updatestate()
state++;
statedelay = 15;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 1;
}
@ -4170,9 +4170,9 @@ void Game::updatestate()
int i = obj.getplayer();
int j = obj.getteleporter();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
if (j != -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[i].xp = obj.entities[j].xp+44;
obj.entities[i].yp = obj.entities[j].yp+44;
@ -4196,7 +4196,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 10;
}
@ -4206,7 +4206,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 10;
}
@ -4216,7 +4216,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 8;
}
@ -4226,7 +4226,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 6;
}
@ -4236,7 +4236,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 3;
}
@ -4247,7 +4247,7 @@ void Game::updatestate()
state++;
statedelay = 15;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 1;
}
@ -4283,9 +4283,9 @@ void Game::updatestate()
int i = obj.getplayer();
int j = obj.getteleporter();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
if (j != -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[i].xp = obj.entities[j].xp+44;
obj.entities[i].yp = obj.entities[j].yp+44;
@ -4309,7 +4309,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 10;
}
@ -4319,7 +4319,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 10;
}
@ -4329,7 +4329,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 8;
}
@ -4339,7 +4339,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 6;
}
@ -4349,7 +4349,7 @@ void Game::updatestate()
{
state++;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 3;
}
@ -4360,7 +4360,7 @@ void Game::updatestate()
state++;
statedelay = 15;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp += 1;
}
@ -5032,7 +5032,7 @@ void Game::deathsequence()
{
i = obj.getplayer();
}
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].colour = 1;
@ -5047,7 +5047,7 @@ void Game::deathsequence()
}
deathcounts++;
music.playef(2);
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].invis = true;
}
@ -5068,7 +5068,7 @@ void Game::deathsequence()
}
}
}
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
if (deathseq == 25) obj.entities[i].invis = true;
if (deathseq == 20) obj.entities[i].invis = true;
@ -5079,7 +5079,7 @@ void Game::deathsequence()
}
if (!nodeathmode)
{
if (i > -1 && deathseq <= 1) obj.entities[i].invis = false;
if (INBOUNDS_VEC(i, obj.entities) && deathseq <= 1) obj.entities[i].invis = false;
}
else
{
@ -7166,7 +7166,7 @@ void Game::returntolab()
graphics.fademode = 4;
map.gotoroom(119, 107);
int player = obj.getplayer();
if (player > -1)
if (INBOUNDS_VEC(player, obj.entities))
{
obj.entities[player].xp = 132;
obj.entities[player].yp = 137;
@ -7179,7 +7179,7 @@ void Game::returntolab()
savex = 132;
savey = 137;
savegc = 0;
if (player > -1)
if (INBOUNDS_VEC(player, obj.entities))
{
savedir = obj.entities[player].dir;
}

View file

@ -13,6 +13,7 @@
#include "Map.h"
#include "Music.h"
#include "Script.h"
#include "UtilityClass.h"
void updatebuttonmappings(int bind)
{
@ -1781,7 +1782,7 @@ void gameinput()
if(map.custommode && !map.custommodeforreal){
if ((game.press_map || key.isDown(27)) && !game.mapheld){
//Return to level editor
if (game.activeactivity > -1 && game.press_map){
if (INBOUNDS_VEC(game.activeactivity, obj.blocks) && game.press_map){
//pass, let code block below handle it
}else if(game.activetele && game.readytotele > 20 && game.press_map){
//pass, let code block below handle it
@ -1824,13 +1825,13 @@ void gameinput()
music.fadeout();
int player = obj.getplayer();
if (player > -1)
if (INBOUNDS_VEC(player, obj.entities))
{
obj.entities[player].colour = 102;
}
int teleporter = obj.getteleporter();
if (teleporter > -1)
if (INBOUNDS_VEC(teleporter, obj.entities))
{
obj.entities[teleporter].tile = 6;
obj.entities[teleporter].colour = 102;
@ -1866,15 +1867,15 @@ void gameinput()
music.fadeout();
int player = obj.getplayer();
if (player > -1)
if (INBOUNDS_VEC(player, obj.entities))
{
obj.entities[player].colour = 102;
}
int companion = obj.getcompanion();
if(companion>-1) obj.entities[companion].colour = 102;
if(INBOUNDS_VEC(companion, obj.entities)) obj.entities[companion].colour = 102;
int teleporter = obj.getteleporter();
if (teleporter > -1)
if (INBOUNDS_VEC(teleporter, obj.entities))
{
obj.entities[teleporter].tile = 6;
obj.entities[teleporter].colour = 102;
@ -1885,7 +1886,7 @@ void gameinput()
}
}
}
else if (game.activeactivity > -1)
else if (INBOUNDS_VEC(game.activeactivity, obj.blocks))
{
enter_already_processed = true;
if((int(std::abs(obj.entities[ie].vx))<=1) && (int(obj.entities[ie].vy) == 0) )
@ -2278,7 +2279,7 @@ void mapmenuactionpress()
game.hascontrol = false;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].colour = 102;
}
@ -2506,13 +2507,13 @@ void teleporterinput()
game.hascontrol = false;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].colour = 102;
}
i = obj.getteleporter();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 6;
obj.entities[i].colour = 102;

View file

@ -289,7 +289,7 @@ void gamelogic()
obj.upsetmode = true;
//change player to sad
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 144;
}
@ -306,7 +306,7 @@ void gamelogic()
obj.upsetmode = false;
//change player to happy
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 0;
}
@ -357,7 +357,7 @@ void gamelogic()
else if (map.cameramode == 4)
{
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
map.cameraseek = map.ypos - (obj.entities[i].yp - 120);
}
@ -378,14 +378,14 @@ void gamelogic()
{
int i = obj.getplayer();
map.ypos -= map.cameraseek;
if (map.cameraseek > 0 && i > -1)
if (map.cameraseek > 0 && INBOUNDS_VEC(i, obj.entities))
{
if (map.ypos < obj.entities[i].yp - 120)
{
map.ypos = obj.entities[i].yp - 120;
}
}
else if (i > -1)
else if (INBOUNDS_VEC(i, obj.entities))
{
if (map.ypos > obj.entities[i].yp - 120)
{
@ -398,7 +398,7 @@ void gamelogic()
else
{
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
map.ypos = obj.entities[i].yp - 120;
}
@ -649,7 +649,7 @@ void gamelogic()
if (game.roomx == 41 + game.scmprogress) //he's in the same room
{
int i = obj.getplayer();
if (i > -1 && obj.entities[i].ax > 0 && obj.entities[i].xp > 280)
if (INBOUNDS_VEC(i, obj.entities) && obj.entities[i].ax > 0 && obj.entities[i].xp > 280)
{
obj.entities[i].ax = 0;
obj.entities[i].dir = 0;
@ -863,7 +863,7 @@ void gamelogic()
{
game.timetrialparlost = true;
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 144;
}
@ -924,7 +924,7 @@ void gamelogic()
//is the player standing on a moving platform?
int i = obj.getplayer();
float j = obj.entitycollideplatformfloor(i);
if (i > -1 && j > -1000)
if (INBOUNDS_VEC(i, obj.entities) && j > -1000)
{
obj.entities[i].newxp = obj.entities[i].xp + j;
obj.entitymapcollision(i);
@ -932,7 +932,7 @@ void gamelogic()
else
{
j = obj.entitycollideplatformroof(i);
if (i > -1 && j > -1000)
if (INBOUNDS_VEC(i, obj.entities) && j > -1000)
{
obj.entities[i].newxp = obj.entities[i].xp + j;
obj.entitymapcollision(i);
@ -957,7 +957,7 @@ void gamelogic()
{
//special for tower: is the player touching any spike blocks?
int player = obj.getplayer();
if(player > -1 && obj.checktowerspikes(player) && graphics.fademode==0)
if(INBOUNDS_VEC(player, obj.entities) && obj.checktowerspikes(player) && graphics.fademode==0)
{
game.deathseq = 30;
}
@ -966,7 +966,7 @@ void gamelogic()
if(map.towermode && game.lifeseq==0)
{
int player = obj.getplayer();
if(!map.invincibility && player > -1)
if(!map.invincibility && INBOUNDS_VEC(player, obj.entities))
{
if (obj.entities[player].yp-map.ypos <= 0)
{
@ -977,7 +977,7 @@ void gamelogic()
game.deathseq = 30;
}
}
else if (player > -1)
else if (INBOUNDS_VEC(player, obj.entities))
{
if (obj.entities[player].yp-map.ypos <= 0)
{
@ -993,7 +993,7 @@ void gamelogic()
}
}
if (player > -1 && obj.entities[player].yp - map.ypos <= 40)
if (INBOUNDS_VEC(player, obj.entities) && obj.entities[player].yp - map.ypos <= 40)
{
map.spikeleveltop++;
if (map.spikeleveltop >= 8) map.spikeleveltop = 8;
@ -1003,7 +1003,7 @@ void gamelogic()
if (map.spikeleveltop > 0) map.spikeleveltop--;
}
if (player > -1 && obj.entities[player].yp - map.ypos >= 164)
if (INBOUNDS_VEC(player, obj.entities) && obj.entities[player].yp - map.ypos >= 164)
{
map.spikelevelbottom++;
if (map.spikelevelbottom >= 8) map.spikelevelbottom = 8;
@ -1026,7 +1026,7 @@ void gamelogic()
obj.customwarpmodevon = false;
int i = obj.getplayer();
if (i > -1 && ((game.door_down > -2 && obj.entities[i].yp >= 226-16) || (game.door_up > -2 && obj.entities[i].yp < -2+16) || (game.door_left > -2 && obj.entities[i].xp < -14+16) || (game.door_right > -2 && obj.entities[i].xp >= 308-16))){
if (INBOUNDS_VEC(i, obj.entities) && ((game.door_down > -2 && obj.entities[i].yp >= 226-16) || (game.door_up > -2 && obj.entities[i].yp < -2+16) || (game.door_left > -2 && obj.entities[i].xp < -14+16) || (game.door_right > -2 && obj.entities[i].xp >= 308-16))){
//Player is leaving room
obj.customwarplinecheck(i);
}
@ -1132,13 +1132,13 @@ void gamelogic()
{
//Normal! Just change room
int player = obj.getplayer();
if (player > -1 && game.door_down > -2 && obj.entities[player].yp >= 238)
if (INBOUNDS_VEC(player, obj.entities) && game.door_down > -2 && obj.entities[player].yp >= 238)
{
obj.entities[player].yp -= 240;
map.gotoroom(game.roomx, game.roomy + 1);
screen_transition = true;
}
if (player > -1 && game.door_up > -2 && obj.entities[player].yp < -2)
if (INBOUNDS_VEC(player, obj.entities) && game.door_up > -2 && obj.entities[player].yp < -2)
{
obj.entities[player].yp += 240;
map.gotoroom(game.roomx, game.roomy - 1);
@ -1150,13 +1150,13 @@ void gamelogic()
{
//Normal! Just change room
int player = obj.getplayer();
if (player > -1 && game.door_left > -2 && obj.entities[player].xp < -14)
if (INBOUNDS_VEC(player, obj.entities) && game.door_left > -2 && obj.entities[player].xp < -14)
{
obj.entities[player].xp += 320;
map.gotoroom(game.roomx - 1, game.roomy);
screen_transition = true;
}
if (player > -1 && game.door_right > -2 && obj.entities[player].xp >= 308)
if (INBOUNDS_VEC(player, obj.entities) && game.door_right > -2 && obj.entities[player].xp >= 308)
{
obj.entities[player].xp -= 320;
map.gotoroom(game.roomx + 1, game.roomy);
@ -1171,12 +1171,12 @@ void gamelogic()
{
//This is minitower 1!
int player = obj.getplayer();
if (player > -1 && game.door_left > -2 && obj.entities[player].xp < -14)
if (INBOUNDS_VEC(player, obj.entities) && game.door_left > -2 && obj.entities[player].xp < -14)
{
obj.entities[player].xp += 320;
map.gotoroom(48, 52);
}
if (player > -1 && game.door_right > -2 && obj.entities[player].xp >= 308)
if (INBOUNDS_VEC(player, obj.entities) && game.door_right > -2 && obj.entities[player].xp >= 308)
{
obj.entities[player].xp -= 320;
obj.entities[player].yp -= (71*8);
@ -1187,7 +1187,7 @@ void gamelogic()
{
//This is minitower 2!
int player = obj.getplayer();
if (player > -1 && game.door_left > -2 && obj.entities[player].xp < -14)
if (INBOUNDS_VEC(player, obj.entities) && game.door_left > -2 && obj.entities[player].xp < -14)
{
if (obj.entities[player].yp > 300)
{
@ -1201,7 +1201,7 @@ void gamelogic()
map.gotoroom(50, 53);
}
}
if (player > -1 && game.door_right > -2 && obj.entities[player].xp >= 308)
if (INBOUNDS_VEC(player, obj.entities) && game.door_right > -2 && obj.entities[player].xp >= 308)
{
obj.entities[player].xp -= 320;
map.gotoroom(52, 53);
@ -1231,13 +1231,13 @@ void gamelogic()
{
//Do not wrap! Instead, go to the correct room
int player = obj.getplayer();
if (player > -1 && game.door_left > -2 && obj.entities[player].xp < -14)
if (INBOUNDS_VEC(player, obj.entities) && game.door_left > -2 && obj.entities[player].xp < -14)
{
obj.entities[player].xp += 320;
obj.entities[player].yp -= (671 * 8);
map.gotoroom(108, 109);
}
if (player > -1 && game.door_right > -2 && obj.entities[player].xp >= 308)
if (INBOUNDS_VEC(player, obj.entities) && game.door_right > -2 && obj.entities[player].xp >= 308)
{
obj.entities[player].xp -= 320;
map.gotoroom(110, 104);
@ -1270,7 +1270,7 @@ void gamelogic()
if (game.roomx == 117 && game.roomy == 102)
{
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].yp = 225;
}
@ -1280,7 +1280,7 @@ void gamelogic()
else if (game.roomx == 119 && game.roomy == 100)
{
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].yp = 225;
}
@ -1290,7 +1290,7 @@ void gamelogic()
else if (game.roomx == 119 && game.roomy == 103)
{
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp = 0;
}
@ -1300,7 +1300,7 @@ void gamelogic()
else if (game.roomx == 116 && game.roomy == 103)
{
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].yp = 225;
}
@ -1310,7 +1310,7 @@ void gamelogic()
else if (game.roomx == 116 && game.roomy == 100)
{
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp = 0;
}
@ -1320,7 +1320,7 @@ void gamelogic()
else if (game.roomx == 114 && game.roomy == 102)
{
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].yp = 225;
}
@ -1407,7 +1407,7 @@ void gamelogic()
//We've changed room? Let's bring our companion along!
game.roomchange = false;
int i = obj.getplayer();
if (game.companion > 0 && i > -1)
if (game.companion > 0 && INBOUNDS_VEC(i, obj.entities))
{
//ok, we'll presume our companion has been destroyed in the room change. So:
switch(game.companion)
@ -1416,7 +1416,7 @@ void gamelogic()
{
obj.createentity(obj.entities[i].xp, 121.0f, 15.0f,1); //Y=121, the floor in that particular place!
int j = obj.getcompanion();
if (j > -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
@ -1435,7 +1435,7 @@ void gamelogic()
obj.createentity(obj.entities[i].xp, 86.0f, 16.0f, 1); //Y=86, the ROOF in that particular place!
}
int j = obj.getcompanion();
if (j > -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
@ -1449,7 +1449,7 @@ void gamelogic()
{
obj.createentity(310, 177, 17, 1);
int j = obj.getcompanion();
if (j > -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
@ -1459,7 +1459,7 @@ void gamelogic()
{
obj.createentity(obj.entities[i].xp, 177.0f, 17.0f, 1);
int j = obj.getcompanion();
if (j > -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
@ -1479,7 +1479,7 @@ void gamelogic()
obj.createentity(obj.entities[i].xp, 185.0f, 18.0f, 15, 0, 1);
}
int j = obj.getcompanion();
if (j > -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
@ -1494,7 +1494,7 @@ void gamelogic()
{
obj.createentity(225.0f, 169.0f, 18, graphics.crewcolour(game.lastsaved), 0, 10);
int j = obj.getcompanion();
if (j > -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
@ -1507,7 +1507,7 @@ void gamelogic()
{
obj.createentity(160.0f, 177.0f, 18, graphics.crewcolour(game.lastsaved), 0, 18, 1);
int j = obj.getcompanion();
if (j > -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
@ -1518,7 +1518,7 @@ void gamelogic()
obj.flags[59] = true;
obj.createentity(obj.entities[i].xp, -20.0f, 18.0f, graphics.crewcolour(game.lastsaved), 0, 10, 0);
int j = obj.getcompanion();
if (j > -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[j].vx = obj.entities[i].vx;
obj.entities[j].dir = obj.entities[i].dir;
@ -1601,7 +1601,7 @@ void gamelogic()
if (game.activetele && !game.advancetext && game.hascontrol && !script.running && !game.intimetrial)
{
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.settemprect(i);
}
@ -1636,7 +1636,7 @@ void gamelogic()
#endif
game.prev_act_fade = game.act_fade;
if (game.activeactivity > -1 && game.hascontrol && !script.running)
if (INBOUNDS_VEC(game.activeactivity, obj.blocks) && game.hascontrol && !script.running)
{
if (game.act_fade < 5)
{
@ -1720,7 +1720,7 @@ void gamelogic()
GhostInfo ghost;
ghost.rx = game.roomx-100;
ghost.ry = game.roomy-100;
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
ghost.x = obj.entities[i].xp;
ghost.y = obj.entities[i].yp;

View file

@ -829,7 +829,7 @@ void mapclass::resetplayer()
game.deathseq = -1;
int i = obj.getplayer();
if(i>-1)
if(INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].vx = 0;
obj.entities[i].vy = 0;
@ -1097,7 +1097,7 @@ void mapclass::gotoroom(int rx, int ry)
//continuations!
temp = obj.getplayer();
if(temp>-1)
if(INBOUNDS_VEC(temp, obj.entities))
{
obj.entities[temp].oldxp = obj.entities[temp].xp - int(obj.entities[temp].vx);
obj.entities[temp].oldyp = obj.entities[temp].yp - int(obj.entities[temp].vy);
@ -1262,7 +1262,7 @@ void mapclass::loadlevel(int rx, int ry)
{
//entered from ground floor
int player = obj.getplayer();
if (player > -1)
if (INBOUNDS_VEC(player, obj.entities))
{
obj.entities[player].yp += (671 * 8);
}
@ -1494,7 +1494,7 @@ void mapclass::loadlevel(int rx, int ry)
tower.loadminitower1();
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].yp += (71 * 8);
}
@ -1539,7 +1539,7 @@ void mapclass::loadlevel(int rx, int ry)
obj.createentity(72, 156, 11, 200); // (horizontal gravity line)
int i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].yp += (71 * 8);
}
@ -2098,8 +2098,8 @@ void mapclass::twoframedelayfix()
|| !custommode
|| game.deathseq != -1
// obj.checktrigger() sets obj.activetrigger and block_idx
|| obj.checktrigger(&block_idx) <= -1
|| block_idx <= -1
|| !INBOUNDS_VEC(obj.checktrigger(&block_idx), obj.entities)
|| !INBOUNDS_VEC(block_idx, obj.blocks)
|| obj.activetrigger < 300)
{
return;

View file

@ -1677,7 +1677,7 @@ void gamerender()
}
float act_alpha = graphics.lerp(game.prev_act_fade, game.act_fade) / 10.0f;
if (game.activeactivity > -1)
if (INBOUNDS_VEC(game.activeactivity, obj.entities))
{
game.activity_lastprompt = obj.blocks[game.activeactivity].prompt;
game.activity_r = obj.blocks[game.activeactivity].r;

View file

@ -98,7 +98,7 @@ void scriptclass::run()
{
//USAGE: moveplayer(x offset, y offset)
int player = obj.getplayer();
if (player > -1)
if (INBOUNDS_VEC(player, obj.entities))
{
obj.entities[player].xp += ss_toi(words[1]);
obj.entities[player].yp += ss_toi(words[2]);
@ -254,7 +254,7 @@ void scriptclass::run()
if (words[0] == "tofloor")
{
int player = obj.getplayer();
if(player > -1 && obj.entities[player].onroof>0)
if(INBOUNDS_VEC(player, obj.entities) && obj.entities[player].onroof>0)
{
game.press_action = true;
scriptdelay = 1;
@ -293,7 +293,7 @@ void scriptclass::run()
{
//USAGE: gotoposition(x position, y position, gravity position)
int player = obj.getplayer();
if (player > -1)
if (INBOUNDS_VEC(player, obj.entities))
{
obj.entities[player].xp = ss_toi(words[1]);
obj.entities[player].yp = ss_toi(words[2]);
@ -429,7 +429,7 @@ void scriptclass::run()
if (words[1] == "player")
{
i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
j = obj.entities[i].dir;
}
@ -485,7 +485,7 @@ void scriptclass::run()
}
//next is whether to position above or below
if (i > -1 && words[2] == "above")
if (INBOUNDS_VEC(i, obj.entities) && words[2] == "above")
{
if (j == 1) //left
{
@ -498,7 +498,7 @@ void scriptclass::run()
texty = obj.entities[i].yp - 18 - (txt.size() * 8);
}
}
else if (i > -1)
else if (INBOUNDS_VEC(i, obj.entities))
{
if (j == 1) //left
{
@ -701,7 +701,7 @@ void scriptclass::run()
{
//Create the super VVVVVV combo!
i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp = 30;
obj.entities[i].yp = 46;
@ -716,7 +716,7 @@ void scriptclass::run()
{
//Create the super VVVVVV combo!
i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp = 100;
obj.entities[i].size = 0;
@ -865,11 +865,11 @@ void scriptclass::run()
i=obj.getcrewman(1);
}
if (i > -1 && ss_toi(words[2]) == 0)
if (INBOUNDS_VEC(i, obj.entities) && ss_toi(words[2]) == 0)
{
obj.entities[i].tile = 0;
}
else if (i > -1)
else if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 144;
}
@ -962,7 +962,7 @@ void scriptclass::run()
i=obj.getcrewman(1);
}
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = ss_toi(words[2]);
}
@ -1045,7 +1045,7 @@ void scriptclass::run()
i=obj.getcrewman(1);
}
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile +=12;
}
@ -1081,11 +1081,11 @@ void scriptclass::run()
i=obj.getcrewman(1);
}
if (i > -1 && ss_toi(words[2]) == 0)
if (INBOUNDS_VEC(i, obj.entities) && ss_toi(words[2]) == 0)
{
obj.entities[i].dir = 0;
}
else if (i > -1)
else if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].dir = 1;
}
@ -1150,7 +1150,7 @@ void scriptclass::run()
}
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].state = ss_toi(words[2]);
if (obj.entities[i].state == 16)
@ -1166,7 +1166,7 @@ void scriptclass::run()
else if (words[0] == "activateteleporter")
{
i = obj.getteleporter();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 6;
obj.entities[i].colour = 102;
@ -1203,7 +1203,7 @@ void scriptclass::run()
i=obj.getcrewman(1);
}
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
if (words[2] == "cyan")
{
@ -1286,7 +1286,7 @@ void scriptclass::run()
{
i = obj.getplayer();
game.savepoint = 0;
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
game.savex = obj.entities[i].xp ;
game.savey = obj.entities[i].yp;
@ -1294,7 +1294,7 @@ void scriptclass::run()
game.savegc = game.gravitycontrol;
game.saverx = game.roomx;
game.savery = game.roomy;
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
game.savedir = obj.entities[i].dir;
}
@ -1463,7 +1463,7 @@ void scriptclass::run()
else if (words[0] == "hideplayer")
{
int player = obj.getplayer();
if (player > -1)
if (INBOUNDS_VEC(player, obj.entities))
{
obj.entities[player].invis = true;
}
@ -1471,7 +1471,7 @@ void scriptclass::run()
else if (words[0] == "showplayer")
{
int player = obj.getplayer();
if (player > -1)
if (INBOUNDS_VEC(player, obj.entities))
{
obj.entities[player].invis = false;
}
@ -1535,7 +1535,7 @@ void scriptclass::run()
obj.resetallflags();
i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].tile = 0;
}
@ -1711,11 +1711,11 @@ void scriptclass::run()
j=obj.getcrewman(1);
}
if (i > -1 && j > -1 && obj.entities[j].xp > obj.entities[i].xp + 5)
if (INBOUNDS_VEC(i, obj.entities) && INBOUNDS_VEC(j, obj.entities) && obj.entities[j].xp > obj.entities[i].xp + 5)
{
obj.entities[i].dir = 1;
}
else if (i > -1 && j > -1 && obj.entities[j].xp < obj.entities[i].xp - 5)
else if (INBOUNDS_VEC(i, obj.entities) && INBOUNDS_VEC(j, obj.entities) && obj.entities[j].xp < obj.entities[i].xp - 5)
{
obj.entities[i].dir = 0;
}
@ -1901,7 +1901,7 @@ void scriptclass::run()
else if (words[0] == "restoreplayercolour")
{
i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].colour = 0;
}
@ -1910,7 +1910,7 @@ void scriptclass::run()
{
i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
if (words[1] == "cyan")
{
@ -1949,7 +1949,7 @@ void scriptclass::run()
else if (words[0] == "activeteleporter")
{
i = obj.getteleporter();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].colour = 101;
}
@ -2718,7 +2718,7 @@ void scriptclass::startgamemode( int t )
map.resetplayer();
i = obj.getplayer();
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
map.ypos = obj.entities[i].yp - 120;
}
@ -3437,7 +3437,7 @@ void scriptclass::teleport()
game.companion = 0;
i = obj.getplayer(); //less likely to have a serious collision error if the player is centered
if (i > -1)
if (INBOUNDS_VEC(i, obj.entities))
{
obj.entities[i].xp = 150;
obj.entities[i].yp = 110;
@ -3460,13 +3460,13 @@ void scriptclass::teleport()
game.gravitycontrol = 0;
map.gotoroom(100+game.teleport_to_x, 100+game.teleport_to_y);
j = obj.getteleporter();
if (j > -1)
if (INBOUNDS_VEC(j, obj.entities))
{
obj.entities[j].state = 2;
}
game.teleport_to_new_area = false;
if (j > -1)
if (INBOUNDS_VEC(j, obj.entities))
{
game.savepoint = obj.entities[j].para;
game.savex = obj.entities[j].xp + 44;
@ -3477,7 +3477,7 @@ void scriptclass::teleport()
game.saverx = game.roomx;
game.savery = game.roomy;
int player = obj.getplayer();
if (player > -1)
if (INBOUNDS_VEC(player, obj.entities))
{
game.savedir = obj.entities[player].dir;
}
@ -3730,7 +3730,7 @@ void scriptclass::hardreset()
i = 100; //previously a for-loop iterating over collect/customcollect set this to 100
int theplayer = obj.getplayer();
if (theplayer > -1){
if (INBOUNDS_VEC(theplayer, obj.entities)){
obj.entities[theplayer].tile = 0;
}