mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2025-01-09 10:29:45 +01:00
Guard all cases obj.getplayer() is used unchecked
obj.getplayer() can return -1, which can cause out-of-bounds indexing of obj.entities, which is really bad. This was by far the most changes, as obj.getplayer() is the most used entity-getting function that returns -1, as well as the most-used function whose sentinel value goes unchecked. To deal with the usage of obj.getplayer() in mapclass::warpto(), I just added general bounds checks inside that function instead of changing all the callers.
This commit is contained in:
parent
08e47e839f
commit
beab344267
7 changed files with 784 additions and 408 deletions
|
@ -2371,8 +2371,9 @@ bool entityclass::updateentities( int i )
|
|||
case 16: //MAVERICK BUS FOLLOWS HIS OWN RULES
|
||||
if (entities[i].state == 0) //Init
|
||||
{
|
||||
int player = getplayer();
|
||||
//first, y position
|
||||
if (entities[getplayer()].yp > 14 * 8)
|
||||
if (player > -1 && entities[player].yp > 14 * 8)
|
||||
{
|
||||
entities[i].tile = 120;
|
||||
entities[i].yp = (28*8)-62;
|
||||
|
@ -2383,7 +2384,7 @@ bool entityclass::updateentities( int i )
|
|||
entities[i].yp = 24;
|
||||
}
|
||||
//now, x position
|
||||
if (entities[getplayer()].xp > 20 * 8)
|
||||
if (player > -1 && entities[player].xp > 20 * 8)
|
||||
{
|
||||
//approach from the left
|
||||
entities[i].xp = -64;
|
||||
|
@ -2592,7 +2593,11 @@ bool entityclass::updateentities( int i )
|
|||
|
||||
game.saverx = game.roomx;
|
||||
game.savery = game.roomy;
|
||||
game.savedir = entities[getplayer()].dir;
|
||||
int player = getplayer();
|
||||
if (player > -1)
|
||||
{
|
||||
game.savedir = entities[player].dir;
|
||||
}
|
||||
entities[i].state = 0;
|
||||
}
|
||||
break;
|
||||
|
@ -2622,11 +2627,11 @@ bool entityclass::updateentities( int i )
|
|||
temp = getplayer();
|
||||
if (game.gravitycontrol == 0)
|
||||
{
|
||||
if (entities[temp].vy < 3) entities[temp].vy = 3;
|
||||
if (temp > -1 && entities[temp].vy < 3) entities[temp].vy = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (entities[temp].vy > -3) entities[temp].vy = -3;
|
||||
if (temp > -1 && entities[temp].vy > -3) entities[temp].vy = -3;
|
||||
}
|
||||
}
|
||||
else if (entities[i].state == 2)
|
||||
|
@ -2679,20 +2684,20 @@ bool entityclass::updateentities( int i )
|
|||
if (entities[k].rule == 7) entities[k].tile = 6;
|
||||
//Stay close to the hero!
|
||||
int j = getplayer();
|
||||
if (entities[j].xp > entities[i].xp + 5)
|
||||
if (j > -1 && entities[j].xp > entities[i].xp + 5)
|
||||
{
|
||||
entities[i].dir = 1;
|
||||
}
|
||||
else if (entities[j].xp < entities[i].xp - 5)
|
||||
else if (j > -1 && entities[j].xp < entities[i].xp - 5)
|
||||
{
|
||||
entities[i].dir = 0;
|
||||
}
|
||||
|
||||
if (entities[j].xp > entities[i].xp + 45)
|
||||
if (j > -1 && entities[j].xp > entities[i].xp + 45)
|
||||
{
|
||||
entities[i].ax = 3;
|
||||
}
|
||||
else if (entities[j].xp < entities[i].xp - 45)
|
||||
else if (j > -1 && entities[j].xp < entities[i].xp - 45)
|
||||
{
|
||||
entities[i].ax = -3;
|
||||
}
|
||||
|
@ -2710,20 +2715,20 @@ bool entityclass::updateentities( int i )
|
|||
{
|
||||
//Basic rules, don't change expression
|
||||
int j = getplayer();
|
||||
if (entities[j].xp > entities[i].xp + 5)
|
||||
if (j > -1 && entities[j].xp > entities[i].xp + 5)
|
||||
{
|
||||
entities[i].dir = 1;
|
||||
}
|
||||
else if (entities[j].xp < entities[i].xp - 5)
|
||||
else if (j > -1 && entities[j].xp < entities[i].xp - 5)
|
||||
{
|
||||
entities[i].dir = 0;
|
||||
}
|
||||
|
||||
if (entities[j].xp > entities[i].xp + 45)
|
||||
if (j > -1 && entities[j].xp > entities[i].xp + 45)
|
||||
{
|
||||
entities[i].ax = 3;
|
||||
}
|
||||
else if (entities[j].xp < entities[i].xp - 45)
|
||||
else if (j > -1 && entities[j].xp < entities[i].xp - 45)
|
||||
{
|
||||
entities[i].ax = -3;
|
||||
}
|
||||
|
@ -2733,20 +2738,20 @@ bool entityclass::updateentities( int i )
|
|||
//Everything from 10 on is for cutscenes
|
||||
//Basic rules, don't change expression
|
||||
int j = getplayer();
|
||||
if (entities[j].xp > entities[i].xp + 5)
|
||||
if (j > -1 && entities[j].xp > entities[i].xp + 5)
|
||||
{
|
||||
entities[i].dir = 1;
|
||||
}
|
||||
else if (entities[j].xp < entities[i].xp - 5)
|
||||
else if (j > -1 && entities[j].xp < entities[i].xp - 5)
|
||||
{
|
||||
entities[i].dir = 0;
|
||||
}
|
||||
|
||||
if (entities[j].xp > entities[i].xp + 45)
|
||||
if (j > -1 && entities[j].xp > entities[i].xp + 45)
|
||||
{
|
||||
entities[i].ax = 3;
|
||||
}
|
||||
else if (entities[j].xp < entities[i].xp - 45)
|
||||
else if (j > -1 && entities[j].xp < entities[i].xp - 45)
|
||||
{
|
||||
entities[i].ax = -3;
|
||||
}
|
||||
|
@ -2890,11 +2895,11 @@ bool entityclass::updateentities( int i )
|
|||
{
|
||||
//Stand still and face the player
|
||||
int j = getplayer();
|
||||
if (entities[j].xp > entities[i].xp + 5)
|
||||
if (j > -1 && entities[j].xp > entities[i].xp + 5)
|
||||
{
|
||||
entities[i].dir = 1;
|
||||
}
|
||||
else if (entities[j].xp < entities[i].xp - 5)
|
||||
else if (j > -1 && entities[j].xp < entities[i].xp - 5)
|
||||
{
|
||||
entities[i].dir = 0;
|
||||
}
|
||||
|
@ -3006,7 +3011,7 @@ bool entityclass::updateentities( int i )
|
|||
{
|
||||
//follow player, but only if he's on the floor!
|
||||
int j = getplayer();
|
||||
if(entities[j].onground>0)
|
||||
if(j > -1 && entities[j].onground>0)
|
||||
{
|
||||
if (entities[j].xp > entities[i].xp + 5)
|
||||
{
|
||||
|
@ -3032,11 +3037,11 @@ bool entityclass::updateentities( int i )
|
|||
}
|
||||
else
|
||||
{
|
||||
if (entities[j].xp > entities[i].xp + 5)
|
||||
if (j > -1 && entities[j].xp > entities[i].xp + 5)
|
||||
{
|
||||
entities[i].dir = 1;
|
||||
}
|
||||
else if (entities[j].xp < entities[i].xp - 5)
|
||||
else if (j > -1 && entities[j].xp < entities[i].xp - 5)
|
||||
{
|
||||
entities[i].dir = 0;
|
||||
}
|
||||
|
@ -3100,7 +3105,7 @@ bool entityclass::updateentities( int i )
|
|||
case 51: //Vertical warp line
|
||||
if (entities[i].state == 2){
|
||||
int j=getplayer();
|
||||
if(entities[j].xp<=307){
|
||||
if(j > -1 && entities[j].xp<=307){
|
||||
customwarpmodevon=false;
|
||||
entities[i].state = 0;
|
||||
}
|
||||
|
@ -3115,7 +3120,7 @@ bool entityclass::updateentities( int i )
|
|||
case 52: //Vertical warp line
|
||||
if (entities[i].state == 2){
|
||||
int j=getplayer();
|
||||
if(entities[j].xp<=307){
|
||||
if(j > -1 && entities[j].xp<=307){
|
||||
customwarpmodevon=false;
|
||||
entities[i].state = 0;
|
||||
}
|
||||
|
@ -3157,11 +3162,11 @@ bool entityclass::updateentities( int i )
|
|||
{
|
||||
//Basic rules, don't change expression
|
||||
int j = getplayer();
|
||||
if (entities[j].xp > entities[i].xp + 5)
|
||||
if (j > -1 && entities[j].xp > entities[i].xp + 5)
|
||||
{
|
||||
entities[i].dir = 1;
|
||||
}
|
||||
else if (entities[j].xp < entities[i].xp - 5)
|
||||
else if (j > -1 && entities[j].xp < entities[i].xp - 5)
|
||||
{
|
||||
entities[i].dir = 0;
|
||||
}
|
||||
|
@ -3226,7 +3231,11 @@ bool entityclass::updateentities( int i )
|
|||
|
||||
game.saverx = game.roomx;
|
||||
game.savery = game.roomy;
|
||||
game.savedir = entities[getplayer()].dir;
|
||||
int player = getplayer();
|
||||
if (player > -1)
|
||||
{
|
||||
game.savedir = entities[player].dir;
|
||||
}
|
||||
entities[i].state = 0;
|
||||
}
|
||||
|
||||
|
@ -4464,7 +4473,7 @@ void entityclass::movingplatformfix( int t )
|
|||
|
||||
//If this intersects the player, then we move the player along it
|
||||
int j = getplayer();
|
||||
if (entitycollide(t, j))
|
||||
if (j > -1 && entitycollide(t, j))
|
||||
{
|
||||
//ok, bollox, let's make sure
|
||||
entities[j].yp = entities[j].yp + int(entities[j].vy);
|
||||
|
@ -4759,7 +4768,7 @@ void entityclass::entitycollisioncheck()
|
|||
//can't have the player being stuck...
|
||||
int j = getplayer();
|
||||
skipdirblocks = true;
|
||||
if (!testwallsx(j, entities[j].xp, entities[j].yp))
|
||||
if (j > -1 && !testwallsx(j, entities[j].xp, entities[j].yp))
|
||||
{
|
||||
//Let's try to get out...
|
||||
if (entities[j].rule == 0)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1605,7 +1605,10 @@ void gameinput()
|
|||
music.fadeout();
|
||||
|
||||
int player = obj.getplayer();
|
||||
obj.entities[player].colour = 102;
|
||||
if (player > -1)
|
||||
{
|
||||
obj.entities[player].colour = 102;
|
||||
}
|
||||
|
||||
int teleporter = obj.getteleporter();
|
||||
if (teleporter > -1)
|
||||
|
@ -1639,7 +1642,10 @@ void gameinput()
|
|||
music.fadeout();
|
||||
|
||||
int player = obj.getplayer();
|
||||
obj.entities[player].colour = 102;
|
||||
if (player > -1)
|
||||
{
|
||||
obj.entities[player].colour = 102;
|
||||
}
|
||||
int companion = obj.getcompanion();
|
||||
if(companion>-1) obj.entities[companion].colour = 102;
|
||||
|
||||
|
@ -1948,7 +1954,10 @@ void mapinput()
|
|||
game.hascontrol = false;
|
||||
|
||||
int i = obj.getplayer();
|
||||
obj.entities[i].colour = 102;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].colour = 102;
|
||||
}
|
||||
|
||||
//which teleporter script do we use? it depends on the companion!
|
||||
game.state = 4000;
|
||||
|
@ -2116,7 +2125,10 @@ void teleporterinput()
|
|||
game.hascontrol = false;
|
||||
|
||||
int i = obj.getplayer();
|
||||
obj.entities[i].colour = 102;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].colour = 102;
|
||||
}
|
||||
|
||||
i = obj.getteleporter();
|
||||
if (i > -1)
|
||||
|
|
|
@ -142,7 +142,10 @@ void gamelogic()
|
|||
obj.upsetmode = true;
|
||||
//change player to sad
|
||||
int i = obj.getplayer();
|
||||
obj.entities[i].tile = 144;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].tile = 144;
|
||||
}
|
||||
music.playef(2);
|
||||
}
|
||||
if (obj.upset > 301) obj.upset = 301;
|
||||
|
@ -156,7 +159,10 @@ void gamelogic()
|
|||
obj.upsetmode = false;
|
||||
//change player to happy
|
||||
int i = obj.getplayer();
|
||||
obj.entities[i].tile = 0;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].tile = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -199,7 +205,10 @@ void gamelogic()
|
|||
else if (map.cameramode == 4)
|
||||
{
|
||||
int i = obj.getplayer();
|
||||
map.cameraseek = map.ypos - (obj.entities[i].yp - 120);
|
||||
if (i > -1)
|
||||
{
|
||||
map.cameraseek = map.ypos - (obj.entities[i].yp - 120);
|
||||
}
|
||||
|
||||
map.cameraseek = map.cameraseek / 10;
|
||||
map.cameraseekframe = 10;
|
||||
|
@ -217,14 +226,14 @@ void gamelogic()
|
|||
{
|
||||
int i = obj.getplayer();
|
||||
map.ypos -= map.cameraseek;
|
||||
if (map.cameraseek > 0)
|
||||
if (map.cameraseek > 0 && i > -1)
|
||||
{
|
||||
if (map.ypos < obj.entities[i].yp - 120)
|
||||
{
|
||||
map.ypos = obj.entities[i].yp - 120;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (i > -1)
|
||||
{
|
||||
if (map.ypos > obj.entities[i].yp - 120)
|
||||
{
|
||||
|
@ -237,7 +246,10 @@ void gamelogic()
|
|||
else
|
||||
{
|
||||
int i = obj.getplayer();
|
||||
map.ypos = obj.entities[i].yp - 120;
|
||||
if (i > -1)
|
||||
{
|
||||
map.ypos = obj.entities[i].yp - 120;
|
||||
}
|
||||
map.bypos = map.ypos / 2;
|
||||
map.cameramode = 0;
|
||||
map.colsuperstate = 0;
|
||||
|
@ -481,7 +493,7 @@ void gamelogic()
|
|||
if (game.roomx == 41 + game.scmprogress) //he's in the same room
|
||||
{
|
||||
int i = obj.getplayer();
|
||||
if (obj.entities[i].ax > 0 && obj.entities[i].xp > 280)
|
||||
if (i > -1 && obj.entities[i].ax > 0 && obj.entities[i].xp > 280)
|
||||
{
|
||||
obj.entities[i].ax = 0;
|
||||
obj.entities[i].dir = 0;
|
||||
|
@ -759,7 +771,7 @@ void gamelogic()
|
|||
//is the player standing on a moving platform?
|
||||
int i = obj.getplayer();
|
||||
float j = obj.entitycollideplatformfloor(i);
|
||||
if (j > -1000)
|
||||
if (i > -1 && j > -1000)
|
||||
{
|
||||
obj.entities[i].newxp = obj.entities[i].xp + j;
|
||||
obj.entitymapcollision(i);
|
||||
|
@ -767,7 +779,7 @@ void gamelogic()
|
|||
else
|
||||
{
|
||||
j = obj.entitycollideplatformroof(i);
|
||||
if (j > -1000)
|
||||
if (i > -1 && j > -1000)
|
||||
{
|
||||
obj.entities[i].newxp = obj.entities[i].xp + j;
|
||||
obj.entitymapcollision(i);
|
||||
|
@ -792,7 +804,7 @@ void gamelogic()
|
|||
{
|
||||
//special for tower: is the player touching any spike blocks?
|
||||
int player = obj.getplayer();
|
||||
if(obj.checktowerspikes(player) && graphics.fademode==0)
|
||||
if(player > -1 && obj.checktowerspikes(player) && graphics.fademode==0)
|
||||
{
|
||||
game.deathseq = 30;
|
||||
}
|
||||
|
@ -801,7 +813,7 @@ void gamelogic()
|
|||
if(map.towermode && game.lifeseq==0)
|
||||
{
|
||||
int player = obj.getplayer();
|
||||
if(!map.invincibility)
|
||||
if(!map.invincibility && player > -1)
|
||||
{
|
||||
if (obj.entities[player].yp-map.ypos <= 0)
|
||||
{
|
||||
|
@ -812,7 +824,7 @@ void gamelogic()
|
|||
game.deathseq = 30;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (player > -1)
|
||||
{
|
||||
if (obj.entities[player].yp-map.ypos <= 0)
|
||||
{
|
||||
|
@ -828,7 +840,7 @@ void gamelogic()
|
|||
}
|
||||
}
|
||||
|
||||
if (obj.entities[player].yp - map.ypos <= 40)
|
||||
if (player > -1 && obj.entities[player].yp - map.ypos <= 40)
|
||||
{
|
||||
map.spikeleveltop++;
|
||||
if (map.spikeleveltop >= 8) map.spikeleveltop = 8;
|
||||
|
@ -838,7 +850,7 @@ void gamelogic()
|
|||
if (map.spikeleveltop > 0) map.spikeleveltop--;
|
||||
}
|
||||
|
||||
if (obj.entities[player].yp - map.ypos >= 164)
|
||||
if (player > -1 && obj.entities[player].yp - map.ypos >= 164)
|
||||
{
|
||||
map.spikelevelbottom++;
|
||||
if (map.spikelevelbottom >= 8) map.spikelevelbottom = 8;
|
||||
|
@ -860,7 +872,7 @@ void gamelogic()
|
|||
obj.customwarpmodevon = false;
|
||||
|
||||
int i = obj.getplayer();
|
||||
if ((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 (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))){
|
||||
//Player is leaving room
|
||||
obj.customwarplinecheck(i);
|
||||
}
|
||||
|
@ -955,12 +967,12 @@ void gamelogic()
|
|||
{
|
||||
//Normal! Just change room
|
||||
int player = obj.getplayer();
|
||||
if (game.door_down > -2 && obj.entities[player].yp >= 238)
|
||||
if (player > -1 && game.door_down > -2 && obj.entities[player].yp >= 238)
|
||||
{
|
||||
obj.entities[player].yp -= 240;
|
||||
map.gotoroom(game.roomx, game.roomy + 1);
|
||||
}
|
||||
if (game.door_up > -2 && obj.entities[player].yp < -2)
|
||||
if (player > -1 && game.door_up > -2 && obj.entities[player].yp < -2)
|
||||
{
|
||||
obj.entities[player].yp += 240;
|
||||
map.gotoroom(game.roomx, game.roomy - 1);
|
||||
|
@ -971,12 +983,12 @@ void gamelogic()
|
|||
{
|
||||
//Normal! Just change room
|
||||
int player = obj.getplayer();
|
||||
if (game.door_left > -2 && obj.entities[player].xp < -14)
|
||||
if (player > -1 && game.door_left > -2 && obj.entities[player].xp < -14)
|
||||
{
|
||||
obj.entities[player].xp += 320;
|
||||
map.gotoroom(game.roomx - 1, game.roomy);
|
||||
}
|
||||
if (game.door_right > -2 && obj.entities[player].xp >= 308)
|
||||
if (player > -1 && game.door_right > -2 && obj.entities[player].xp >= 308)
|
||||
{
|
||||
obj.entities[player].xp -= 320;
|
||||
map.gotoroom(game.roomx + 1, game.roomy);
|
||||
|
@ -990,12 +1002,12 @@ void gamelogic()
|
|||
{
|
||||
//This is minitower 1!
|
||||
int player = obj.getplayer();
|
||||
if (game.door_left > -2 && obj.entities[player].xp < -14)
|
||||
if (player > -1 && game.door_left > -2 && obj.entities[player].xp < -14)
|
||||
{
|
||||
obj.entities[player].xp += 320;
|
||||
map.gotoroom(48, 52);
|
||||
}
|
||||
if (game.door_right > -2 && obj.entities[player].xp >= 308)
|
||||
if (player > -1 && game.door_right > -2 && obj.entities[player].xp >= 308)
|
||||
{
|
||||
obj.entities[player].xp -= 320;
|
||||
obj.entities[player].yp -= (71*8);
|
||||
|
@ -1006,7 +1018,7 @@ void gamelogic()
|
|||
{
|
||||
//This is minitower 2!
|
||||
int player = obj.getplayer();
|
||||
if (game.door_left > -2 && obj.entities[player].xp < -14)
|
||||
if (player > -1 && game.door_left > -2 && obj.entities[player].xp < -14)
|
||||
{
|
||||
if (obj.entities[player].yp > 300)
|
||||
{
|
||||
|
@ -1020,7 +1032,7 @@ void gamelogic()
|
|||
map.gotoroom(50, 53);
|
||||
}
|
||||
}
|
||||
if (game.door_right > -2 && obj.entities[player].xp >= 308)
|
||||
if (player > -1 && game.door_right > -2 && obj.entities[player].xp >= 308)
|
||||
{
|
||||
obj.entities[player].xp -= 320;
|
||||
map.gotoroom(52, 53);
|
||||
|
@ -1051,13 +1063,13 @@ void gamelogic()
|
|||
{
|
||||
//Do not wrap! Instead, go to the correct room
|
||||
int player = obj.getplayer();
|
||||
if (game.door_left > -2 && obj.entities[player].xp < -14)
|
||||
if (player > -1 && 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 (game.door_right > -2 && obj.entities[player].xp >= 308)
|
||||
if (player > -1 && game.door_right > -2 && obj.entities[player].xp >= 308)
|
||||
{
|
||||
obj.entities[player].xp -= 320;
|
||||
map.gotoroom(110, 104);
|
||||
|
@ -1090,42 +1102,60 @@ void gamelogic()
|
|||
if (game.roomx == 117 && game.roomy == 102)
|
||||
{
|
||||
int i = obj.getplayer();
|
||||
obj.entities[i].yp = 225;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].yp = 225;
|
||||
}
|
||||
map.gotoroom(119, 100);
|
||||
game.teleport = false;
|
||||
}
|
||||
else if (game.roomx == 119 && game.roomy == 100)
|
||||
{
|
||||
int i = obj.getplayer();
|
||||
obj.entities[i].yp = 225;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].yp = 225;
|
||||
}
|
||||
map.gotoroom(119, 103);
|
||||
game.teleport = false;
|
||||
}
|
||||
else if (game.roomx == 119 && game.roomy == 103)
|
||||
{
|
||||
int i = obj.getplayer();
|
||||
obj.entities[i].xp = 0;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].xp = 0;
|
||||
}
|
||||
map.gotoroom(116, 103);
|
||||
game.teleport = false;
|
||||
}
|
||||
else if (game.roomx == 116 && game.roomy == 103)
|
||||
{
|
||||
int i = obj.getplayer();
|
||||
obj.entities[i].yp = 225;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].yp = 225;
|
||||
}
|
||||
map.gotoroom(116, 100);
|
||||
game.teleport = false;
|
||||
}
|
||||
else if (game.roomx == 116 && game.roomy == 100)
|
||||
{
|
||||
int i = obj.getplayer();
|
||||
obj.entities[i].xp = 0;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].xp = 0;
|
||||
}
|
||||
map.gotoroom(114, 102);
|
||||
game.teleport = false;
|
||||
}
|
||||
else if (game.roomx == 114 && game.roomy == 102)
|
||||
{
|
||||
int i = obj.getplayer();
|
||||
obj.entities[i].yp = 225;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].yp = 225;
|
||||
}
|
||||
map.gotoroom(113, 100);
|
||||
game.teleport = false;
|
||||
}
|
||||
|
@ -1187,9 +1217,9 @@ void gamelogic()
|
|||
{
|
||||
//We've changed room? Let's bring our companion along!
|
||||
game.roomchange = false;
|
||||
if (game.companion > 0)
|
||||
int i = obj.getplayer();
|
||||
if (game.companion > 0 && i > -1)
|
||||
{
|
||||
int i = obj.getplayer();
|
||||
//ok, we'll presume our companion has been destroyed in the room change. So:
|
||||
switch(game.companion)
|
||||
{
|
||||
|
@ -1355,7 +1385,10 @@ void gamelogic()
|
|||
if (game.activetele)
|
||||
{
|
||||
int i = obj.getplayer();
|
||||
obj.settemprect(i);
|
||||
if (i > -1)
|
||||
{
|
||||
obj.settemprect(i);
|
||||
}
|
||||
if (help.intersects(game.teleblock, obj.temprect))
|
||||
{
|
||||
game.readytotele += 25;
|
||||
|
|
|
@ -825,8 +825,11 @@ void mapclass::warpto(int rx, int ry , int t, int tx, int ty)
|
|||
{
|
||||
gotoroom(rx, ry);
|
||||
game.teleport = false;
|
||||
obj.entities[t].xp = tx * 8;
|
||||
obj.entities[t].yp = (ty * 8) - obj.entities[t].h;
|
||||
if (t >= 0 && t < (int) obj.entities.size())
|
||||
{
|
||||
obj.entities[t].xp = tx * 8;
|
||||
obj.entities[t].yp = (ty * 8) - obj.entities[t].h;
|
||||
}
|
||||
game.gravitycontrol = 0;
|
||||
}
|
||||
|
||||
|
@ -1191,7 +1194,10 @@ void mapclass::loadlevel(int rx, int ry)
|
|||
{
|
||||
//entered from ground floor
|
||||
int player = obj.getplayer();
|
||||
obj.entities[player].yp += (671 * 8);
|
||||
if (player > -1)
|
||||
{
|
||||
obj.entities[player].yp += (671 * 8);
|
||||
}
|
||||
|
||||
ypos = (700-29) * 8;
|
||||
bypos = ypos / 2;
|
||||
|
@ -1392,7 +1398,10 @@ void mapclass::loadlevel(int rx, int ry)
|
|||
tower.loadminitower1();
|
||||
|
||||
int i = obj.getplayer();
|
||||
obj.entities[i].yp += (71 * 8);
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].yp += (71 * 8);
|
||||
}
|
||||
game.roomy--;
|
||||
finaly--;
|
||||
|
||||
|
@ -1433,7 +1442,10 @@ void mapclass::loadlevel(int rx, int ry)
|
|||
obj.createentity(72, 156, 11, 200); // (horizontal gravity line)
|
||||
|
||||
int i = obj.getplayer();
|
||||
obj.entities[i].yp += (71 * 8);
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].yp += (71 * 8);
|
||||
}
|
||||
game.roomy--;
|
||||
finaly--;
|
||||
|
||||
|
@ -1907,11 +1919,11 @@ void mapclass::loadlevel(int rx, int ry)
|
|||
{
|
||||
//face the player
|
||||
j = obj.getplayer();
|
||||
if (obj.entities[j].xp > obj.entities[i].xp + 5)
|
||||
if (j > -1 && obj.entities[j].xp > obj.entities[i].xp + 5)
|
||||
{
|
||||
obj.entities[i].dir = 1;
|
||||
}
|
||||
else if (obj.entities[j].xp < obj.entities[i].xp - 5)
|
||||
else if (j > -1 && obj.entities[j].xp < obj.entities[i].xp - 5)
|
||||
{
|
||||
obj.entities[i].dir = 0;
|
||||
}
|
||||
|
|
|
@ -1394,10 +1394,13 @@ void gamerender()
|
|||
GhostInfo ghost;
|
||||
ghost.rx = game.roomx-100;
|
||||
ghost.ry = game.roomy-100;
|
||||
ghost.x = obj.entities[i].xp;
|
||||
ghost.y = obj.entities[i].yp;
|
||||
ghost.col = obj.entities[i].colour;
|
||||
ghost.frame = obj.entities[i].drawframe;
|
||||
if (i > -1)
|
||||
{
|
||||
ghost.x = obj.entities[i].xp;
|
||||
ghost.y = obj.entities[i].yp;
|
||||
ghost.col = obj.entities[i].colour;
|
||||
ghost.frame = obj.entities[i].drawframe;
|
||||
}
|
||||
ed.ghosts.push_back(ghost);
|
||||
}
|
||||
if (ed.ghosts.size() > 100)
|
||||
|
|
|
@ -84,8 +84,11 @@ void scriptclass::run()
|
|||
{
|
||||
//USAGE: moveplayer(x offset, y offset)
|
||||
int player = obj.getplayer();
|
||||
obj.entities[player].xp += ss_toi(words[1]);
|
||||
obj.entities[player].yp += ss_toi(words[2]);
|
||||
if (player > -1)
|
||||
{
|
||||
obj.entities[player].xp += ss_toi(words[1]);
|
||||
obj.entities[player].yp += ss_toi(words[2]);
|
||||
}
|
||||
scriptdelay = 1;
|
||||
}
|
||||
#if !defined(NO_CUSTOM_LEVELS)
|
||||
|
@ -230,7 +233,8 @@ void scriptclass::run()
|
|||
}
|
||||
if (words[0] == "tofloor")
|
||||
{
|
||||
if(obj.entities[obj.getplayer()].onroof>0)
|
||||
int player = obj.getplayer();
|
||||
if(player > -1 && obj.entities[player].onroof>0)
|
||||
{
|
||||
game.press_action = true;
|
||||
scriptdelay = 1;
|
||||
|
@ -270,8 +274,11 @@ void scriptclass::run()
|
|||
{
|
||||
//USAGE: gotoposition(x position, y position, gravity position)
|
||||
int player = obj.getplayer();
|
||||
obj.entities[player].xp = ss_toi(words[1]);
|
||||
obj.entities[player].yp = ss_toi(words[2]);
|
||||
if (player > -1)
|
||||
{
|
||||
obj.entities[player].xp = ss_toi(words[1]);
|
||||
obj.entities[player].yp = ss_toi(words[2]);
|
||||
}
|
||||
game.gravitycontrol = ss_toi(words[3]);
|
||||
|
||||
}
|
||||
|
@ -391,7 +398,10 @@ void scriptclass::run()
|
|||
if (words[1] == "player")
|
||||
{
|
||||
i = obj.getplayer();
|
||||
j = obj.entities[i].dir;
|
||||
if (i > -1)
|
||||
{
|
||||
j = obj.entities[i].dir;
|
||||
}
|
||||
}
|
||||
else if (words[1] == "cyan")
|
||||
{
|
||||
|
@ -444,7 +454,7 @@ void scriptclass::run()
|
|||
}
|
||||
|
||||
//next is whether to position above or below
|
||||
if (words[2] == "above")
|
||||
if (i > -1 && words[2] == "above")
|
||||
{
|
||||
if (j == 1) //left
|
||||
{
|
||||
|
@ -457,7 +467,7 @@ void scriptclass::run()
|
|||
texty = obj.entities[i].yp - 18 - (txt.size() * 8);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (i > -1)
|
||||
{
|
||||
if (j == 1) //left
|
||||
{
|
||||
|
@ -660,24 +670,30 @@ void scriptclass::run()
|
|||
{
|
||||
//Create the super VVVVVV combo!
|
||||
i = obj.getplayer();
|
||||
obj.entities[i].xp = 30;
|
||||
obj.entities[i].yp = 46;
|
||||
obj.entities[i].size = 13;
|
||||
obj.entities[i].colour = 23;
|
||||
obj.entities[i].cx = 36;// 6;
|
||||
obj.entities[i].cy = 12+80;// 2;
|
||||
obj.entities[i].h = 126-80;// 21;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].xp = 30;
|
||||
obj.entities[i].yp = 46;
|
||||
obj.entities[i].size = 13;
|
||||
obj.entities[i].colour = 23;
|
||||
obj.entities[i].cx = 36;// 6;
|
||||
obj.entities[i].cy = 12+80;// 2;
|
||||
obj.entities[i].h = 126-80;// 21;
|
||||
}
|
||||
}
|
||||
else if (words[0] == "undovvvvvvman")
|
||||
{
|
||||
//Create the super VVVVVV combo!
|
||||
i = obj.getplayer();
|
||||
obj.entities[i].xp = 100;
|
||||
obj.entities[i].size = 0;
|
||||
obj.entities[i].colour = 0;
|
||||
obj.entities[i].cx = 6;
|
||||
obj.entities[i].cy = 2;
|
||||
obj.entities[i].h = 21;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].xp = 100;
|
||||
obj.entities[i].size = 0;
|
||||
obj.entities[i].colour = 0;
|
||||
obj.entities[i].cx = 6;
|
||||
obj.entities[i].cy = 2;
|
||||
obj.entities[i].h = 21;
|
||||
}
|
||||
}
|
||||
else if (words[0] == "createentity")
|
||||
{
|
||||
|
@ -796,11 +812,11 @@ void scriptclass::run()
|
|||
i=obj.getcrewman(1);
|
||||
}
|
||||
|
||||
if (ss_toi(words[2]) == 0)
|
||||
if (i > -1 && ss_toi(words[2]) == 0)
|
||||
{
|
||||
obj.entities[i].tile = 0;
|
||||
}
|
||||
else
|
||||
else if (i > -1)
|
||||
{
|
||||
obj.entities[i].tile = 144;
|
||||
}
|
||||
|
@ -893,7 +909,10 @@ void scriptclass::run()
|
|||
i=obj.getcrewman(1);
|
||||
}
|
||||
|
||||
obj.entities[i].tile = ss_toi(words[2]);
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].tile = ss_toi(words[2]);
|
||||
}
|
||||
}
|
||||
else if (words[0] == "flipgravity")
|
||||
{
|
||||
|
@ -973,7 +992,10 @@ void scriptclass::run()
|
|||
i=obj.getcrewman(1);
|
||||
}
|
||||
|
||||
obj.entities[i].tile +=12;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].tile +=12;
|
||||
}
|
||||
}
|
||||
else if (words[0] == "changedir")
|
||||
{
|
||||
|
@ -1006,11 +1028,11 @@ void scriptclass::run()
|
|||
i=obj.getcrewman(1);
|
||||
}
|
||||
|
||||
if (ss_toi(words[2]) == 0)
|
||||
if (i > -1 && ss_toi(words[2]) == 0)
|
||||
{
|
||||
obj.entities[i].dir = 0;
|
||||
}
|
||||
else
|
||||
else if (i > -1)
|
||||
{
|
||||
obj.entities[i].dir = 1;
|
||||
}
|
||||
|
@ -1075,14 +1097,17 @@ void scriptclass::run()
|
|||
}
|
||||
|
||||
|
||||
obj.entities[i].state = ss_toi(words[2]);
|
||||
if (obj.entities[i].state == 16)
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].para=ss_toi(words[3]);
|
||||
}
|
||||
else if (obj.entities[i].state == 17)
|
||||
{
|
||||
obj.entities[i].dir=ss_toi(words[3]);
|
||||
obj.entities[i].state = ss_toi(words[2]);
|
||||
if (obj.entities[i].state == 16)
|
||||
{
|
||||
obj.entities[i].para=ss_toi(words[3]);
|
||||
}
|
||||
else if (obj.entities[i].state == 17)
|
||||
{
|
||||
obj.entities[i].dir=ss_toi(words[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (words[0] == "alarmon")
|
||||
|
@ -1134,33 +1159,36 @@ void scriptclass::run()
|
|||
i=obj.getcrewman(1);
|
||||
}
|
||||
|
||||
if (words[2] == "cyan")
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].colour = 0;
|
||||
}
|
||||
else if (words[2] == "red")
|
||||
{
|
||||
obj.entities[i].colour = 15;
|
||||
}
|
||||
else if (words[2] == "green")
|
||||
{
|
||||
obj.entities[i].colour = 13;
|
||||
}
|
||||
else if (words[2] == "yellow")
|
||||
{
|
||||
obj.entities[i].colour = 14;
|
||||
}
|
||||
else if (words[2] == "blue")
|
||||
{
|
||||
obj.entities[i].colour = 16;
|
||||
}
|
||||
else if (words[2] == "purple")
|
||||
{
|
||||
obj.entities[i].colour = 20;
|
||||
}
|
||||
else if (words[2] == "teleporter")
|
||||
{
|
||||
obj.entities[i].colour = 102;
|
||||
if (words[2] == "cyan")
|
||||
{
|
||||
obj.entities[i].colour = 0;
|
||||
}
|
||||
else if (words[2] == "red")
|
||||
{
|
||||
obj.entities[i].colour = 15;
|
||||
}
|
||||
else if (words[2] == "green")
|
||||
{
|
||||
obj.entities[i].colour = 13;
|
||||
}
|
||||
else if (words[2] == "yellow")
|
||||
{
|
||||
obj.entities[i].colour = 14;
|
||||
}
|
||||
else if (words[2] == "blue")
|
||||
{
|
||||
obj.entities[i].colour = 16;
|
||||
}
|
||||
else if (words[2] == "purple")
|
||||
{
|
||||
obj.entities[i].colour = 20;
|
||||
}
|
||||
else if (words[2] == "teleporter")
|
||||
{
|
||||
obj.entities[i].colour = 102;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (words[0] == "squeak")
|
||||
|
@ -1214,12 +1242,18 @@ void scriptclass::run()
|
|||
{
|
||||
i = obj.getplayer();
|
||||
game.savepoint = 0;
|
||||
game.savex = obj.entities[i].xp ;
|
||||
game.savey = obj.entities[i].yp;
|
||||
if (i > -1)
|
||||
{
|
||||
game.savex = obj.entities[i].xp ;
|
||||
game.savey = obj.entities[i].yp;
|
||||
}
|
||||
game.savegc = game.gravitycontrol;
|
||||
game.saverx = game.roomx;
|
||||
game.savery = game.roomy;
|
||||
game.savedir = obj.entities[i].dir;
|
||||
if (i > -1)
|
||||
{
|
||||
game.savedir = obj.entities[i].dir;
|
||||
}
|
||||
}
|
||||
else if (words[0] == "gamestate")
|
||||
{
|
||||
|
@ -1368,11 +1402,19 @@ void scriptclass::run()
|
|||
}
|
||||
else if (words[0] == "hideplayer")
|
||||
{
|
||||
obj.entities[obj.getplayer()].invis = true;
|
||||
int player = obj.getplayer();
|
||||
if (player > -1)
|
||||
{
|
||||
obj.entities[player].invis = true;
|
||||
}
|
||||
}
|
||||
else if (words[0] == "showplayer")
|
||||
{
|
||||
obj.entities[obj.getplayer()].invis = false;
|
||||
int player = obj.getplayer();
|
||||
if (player > -1)
|
||||
{
|
||||
obj.entities[player].invis = false;
|
||||
}
|
||||
}
|
||||
else if (words[0] == "teleportscript")
|
||||
{
|
||||
|
@ -1433,7 +1475,10 @@ void scriptclass::run()
|
|||
|
||||
obj.resetallflags();
|
||||
i = obj.getplayer();
|
||||
obj.entities[i].tile = 0;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].tile = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
|
@ -1606,11 +1651,11 @@ void scriptclass::run()
|
|||
j=obj.getcrewman(1);
|
||||
}
|
||||
|
||||
if (obj.entities[j].xp > obj.entities[i].xp + 5)
|
||||
if (i > -1 && j > -1 && obj.entities[j].xp > obj.entities[i].xp + 5)
|
||||
{
|
||||
obj.entities[i].dir = 1;
|
||||
}
|
||||
else if (obj.entities[j].xp < obj.entities[i].xp - 5)
|
||||
else if (i > -1 && j > -1 && obj.entities[j].xp < obj.entities[i].xp - 5)
|
||||
{
|
||||
obj.entities[i].dir = 0;
|
||||
}
|
||||
|
@ -1796,39 +1841,45 @@ void scriptclass::run()
|
|||
else if (words[0] == "restoreplayercolour")
|
||||
{
|
||||
i = obj.getplayer();
|
||||
obj.entities[i].colour = 0;
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].colour = 0;
|
||||
}
|
||||
}
|
||||
else if (words[0] == "changeplayercolour")
|
||||
{
|
||||
i = obj.getplayer();
|
||||
|
||||
if (words[1] == "cyan")
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].colour = 0;
|
||||
}
|
||||
else if (words[1] == "red")
|
||||
{
|
||||
obj.entities[i].colour = 15;
|
||||
}
|
||||
else if (words[1] == "green")
|
||||
{
|
||||
obj.entities[i].colour = 13;
|
||||
}
|
||||
else if (words[1] == "yellow")
|
||||
{
|
||||
obj.entities[i].colour = 14;
|
||||
}
|
||||
else if (words[1] == "blue")
|
||||
{
|
||||
obj.entities[i].colour = 16;
|
||||
}
|
||||
else if (words[1] == "purple")
|
||||
{
|
||||
obj.entities[i].colour = 20;
|
||||
}
|
||||
else if (words[1] == "teleporter")
|
||||
{
|
||||
obj.entities[i].colour = 102;
|
||||
if (words[1] == "cyan")
|
||||
{
|
||||
obj.entities[i].colour = 0;
|
||||
}
|
||||
else if (words[1] == "red")
|
||||
{
|
||||
obj.entities[i].colour = 15;
|
||||
}
|
||||
else if (words[1] == "green")
|
||||
{
|
||||
obj.entities[i].colour = 13;
|
||||
}
|
||||
else if (words[1] == "yellow")
|
||||
{
|
||||
obj.entities[i].colour = 14;
|
||||
}
|
||||
else if (words[1] == "blue")
|
||||
{
|
||||
obj.entities[i].colour = 16;
|
||||
}
|
||||
else if (words[1] == "purple")
|
||||
{
|
||||
obj.entities[i].colour = 20;
|
||||
}
|
||||
else if (words[1] == "teleporter")
|
||||
{
|
||||
obj.entities[i].colour = 102;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (words[0] == "altstates")
|
||||
|
@ -2585,7 +2636,10 @@ void scriptclass::startgamemode( int t )
|
|||
map.resetplayer();
|
||||
|
||||
i = obj.getplayer();
|
||||
map.ypos = obj.entities[i].yp - 120;
|
||||
if (i > -1)
|
||||
{
|
||||
map.ypos = obj.entities[i].yp - 120;
|
||||
}
|
||||
map.bypos = map.ypos / 2;
|
||||
map.cameramode = 0;
|
||||
map.colsuperstate = 0;
|
||||
|
@ -3278,9 +3332,12 @@ void scriptclass::teleport()
|
|||
game.companion = 0;
|
||||
|
||||
i = obj.getplayer(); //less likely to have a serious collision error if the player is centered
|
||||
obj.entities[i].xp = 150;
|
||||
obj.entities[i].yp = 110;
|
||||
if(game.teleport_to_x==17 && game.teleport_to_y==17) obj.entities[i].xp = 88; //prevent falling!
|
||||
if (i > -1)
|
||||
{
|
||||
obj.entities[i].xp = 150;
|
||||
obj.entities[i].yp = 110;
|
||||
if(game.teleport_to_x==17 && game.teleport_to_y==17) obj.entities[i].xp = 88; //prevent falling!
|
||||
}
|
||||
|
||||
if (game.teleportscript == "levelonecomplete")
|
||||
{
|
||||
|
@ -3312,7 +3369,11 @@ void scriptclass::teleport()
|
|||
|
||||
game.saverx = game.roomx;
|
||||
game.savery = game.roomy;
|
||||
game.savedir = obj.entities[obj.getplayer()].dir;
|
||||
int player = obj.getplayer();
|
||||
if (player > -1)
|
||||
{
|
||||
game.savedir = obj.entities[player].dir;
|
||||
}
|
||||
|
||||
if(game.teleport_to_x==0 && game.teleport_to_y==0)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue