mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 01:59:43 +01:00
Refactor explored rooms to use setters and getters
This makes it easier to add bounds checks to all accesses of map.explored. Also, all manually-written existing bounds checks have been removed, because they're going to go into the new getters and setters. The getter is mapclass::isexplored() and the setter is mapclass::setexplored().
This commit is contained in:
parent
b340a6ccc4
commit
c5e999c1d5
5 changed files with 66 additions and 61 deletions
|
@ -2413,7 +2413,7 @@ void teleporterinput(void)
|
|||
{
|
||||
point& tele = map.teleporters[i];
|
||||
|
||||
if (map.explored[tele.x + tele.y*20])
|
||||
if (map.isexplored(tele.x, tele.y))
|
||||
{
|
||||
any_tele_unlocked = true;
|
||||
break;
|
||||
|
@ -2430,7 +2430,7 @@ void teleporterinput(void)
|
|||
tempx = map.teleporters[game.teleport_to_teleporter].x;
|
||||
tempy = map.teleporters[game.teleport_to_teleporter].y;
|
||||
}
|
||||
while (map.explored[tempx + (20 * tempy)] == 0);
|
||||
while (!map.isexplored(tempx, tempy));
|
||||
}
|
||||
else if (game.press_right && any_tele_unlocked)
|
||||
{
|
||||
|
@ -2441,7 +2441,7 @@ void teleporterinput(void)
|
|||
tempx = map.teleporters[game.teleport_to_teleporter].x;
|
||||
tempy = map.teleporters[game.teleport_to_teleporter].y;
|
||||
}
|
||||
while (map.explored[tempx + (20 * tempy)] == 0);
|
||||
while (!map.isexplored(tempx, tempy));
|
||||
}
|
||||
|
||||
if (game.press_map)
|
||||
|
|
|
@ -721,34 +721,46 @@ int mapclass::area(int _rx, int _ry)
|
|||
}
|
||||
}
|
||||
|
||||
bool mapclass::isexplored(const int rx, const int ry)
|
||||
{
|
||||
const int roomnum = rx + ry*20;
|
||||
return explored[roomnum];
|
||||
}
|
||||
|
||||
void mapclass::setexplored(const int rx, const int ry, const bool status)
|
||||
{
|
||||
const int roomnum = rx + ry*20;
|
||||
explored[roomnum] = status;
|
||||
}
|
||||
|
||||
void mapclass::exploretower(void)
|
||||
{
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
explored[9 + (i * 20)] = 1;
|
||||
setexplored(9, i, true);
|
||||
}
|
||||
}
|
||||
|
||||
void mapclass::hideship(void)
|
||||
{
|
||||
//remove the ship from the explored areas
|
||||
explored[2 + (10 * 20)] = 0;
|
||||
explored[3 + (10 * 20)] = 0;
|
||||
explored[4 + (10 * 20)] = 0;
|
||||
explored[2 + (11 * 20)] = 0;
|
||||
explored[3 + (11 * 20)] = 0;
|
||||
explored[4 + (11 * 20)] = 0;
|
||||
setexplored(2, 10, false);
|
||||
setexplored(3, 10, false);
|
||||
setexplored(4, 10, false);
|
||||
setexplored(2, 11, false);
|
||||
setexplored(3, 11, false);
|
||||
setexplored(4, 11, false);
|
||||
}
|
||||
|
||||
void mapclass::showship(void)
|
||||
{
|
||||
//remove the ship from the explored areas
|
||||
explored[2 + (10 * 20)] = 1;
|
||||
explored[3 + (10 * 20)] = 1;
|
||||
explored[4 + (10 * 20)] = 1;
|
||||
explored[2 + (11 * 20)] = 1;
|
||||
explored[3 + (11 * 20)] = 1;
|
||||
explored[4 + (11 * 20)] = 1;
|
||||
//show the ship in the explored areas
|
||||
setexplored(2, 10, true);
|
||||
setexplored(3, 10, true);
|
||||
setexplored(4, 10, true);
|
||||
setexplored(2, 11, true);
|
||||
setexplored(3, 11, true);
|
||||
setexplored(4, 11, true);
|
||||
}
|
||||
|
||||
void mapclass::resetplayer(void)
|
||||
|
@ -1148,7 +1160,7 @@ void mapclass::loadlevel(int rx, int ry)
|
|||
int t;
|
||||
if (!finalmode)
|
||||
{
|
||||
explored[rx - 100 + ((ry - 100) * 20)] = true;
|
||||
setexplored(rx - 100, ry - 100, true);
|
||||
if (rx == 109 && !custommode)
|
||||
{
|
||||
exploretower();
|
||||
|
|
|
@ -92,6 +92,9 @@ public:
|
|||
bool explored[20 * 20];
|
||||
int vmult[30];
|
||||
|
||||
bool isexplored(const int rx, const int ry);
|
||||
void setexplored(const int rx, const int ry, const bool status);
|
||||
|
||||
int background;
|
||||
int rcol;
|
||||
int tileset;
|
||||
|
|
|
@ -1813,7 +1813,7 @@ void maprender(void)
|
|||
if(map.customzoom==4){
|
||||
for (int j = 0; j < map.customheight; j++){
|
||||
for (int i = 0; i < map.customwidth; i++){
|
||||
if(map.explored[i+(j*20)]==0){
|
||||
if(!map.isexplored(i, j)){
|
||||
//Draw the fog of war on the map
|
||||
graphics.drawimage(2, map.custommmxoff+40 + (i * 48), map.custommmyoff+21 + (j * 36), false);
|
||||
graphics.drawimage(2, map.custommmxoff+40 + 12 + (i * 48), map.custommmyoff+21 + (j * 36), false);
|
||||
|
@ -1840,7 +1840,7 @@ void maprender(void)
|
|||
}else if(map.customzoom==2){
|
||||
for (int j = 0; j < map.customheight; j++){
|
||||
for (int i = 0; i < map.customwidth; i++){
|
||||
if(map.explored[i+(j*20)]==0){
|
||||
if(!map.isexplored(i, j)){
|
||||
//Draw the fog of war on the map
|
||||
graphics.drawimage(2, map.custommmxoff+40 + (i * 24), map.custommmyoff+21 + (j * 18), false);
|
||||
graphics.drawimage(2, map.custommmxoff+40 + 12 + (i * 24), map.custommmyoff+21 + (j * 18), false);
|
||||
|
@ -1852,7 +1852,7 @@ void maprender(void)
|
|||
}else{
|
||||
for (int j = 0; j < map.customheight; j++){
|
||||
for (int i = 0; i < map.customwidth; i++){
|
||||
if(map.explored[i+(j*20)]==0){
|
||||
if(!map.isexplored(i, j)){
|
||||
//Draw the fog of war on the map
|
||||
graphics.drawimage(2, map.custommmxoff+40 + (i * 12), map.custommmyoff+21 + (j * 9), false);
|
||||
}
|
||||
|
@ -1923,7 +1923,7 @@ void maprender(void)
|
|||
{
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
if(map.explored[i+(j*20)]==0)
|
||||
if(!map.isexplored(i, j))
|
||||
{
|
||||
//Draw the fog of war on the map
|
||||
graphics.drawimage(2, 40 + (i * 12), 21 + (j * 9), false);
|
||||
|
@ -1973,15 +1973,15 @@ void maprender(void)
|
|||
//draw legend details
|
||||
for (size_t i = 0; i < map.teleporters.size(); i++)
|
||||
{
|
||||
if (map.showteleporters && map.explored[map.teleporters[i].x + (20 * map.teleporters[i].y)] > 0)
|
||||
if (map.showteleporters && map.isexplored(map.teleporters[i].x, map.teleporters[i].y))
|
||||
{
|
||||
int temp = 1126 + map.explored[map.teleporters[i].x + (20 * map.teleporters[i].y)];
|
||||
int temp = 1126 + (int) map.isexplored(map.teleporters[i].x, map.teleporters[i].y);
|
||||
if (graphics.flipmode) temp += 3;
|
||||
graphics.drawtile(40 + 3 + (map.teleporters[i].x * 12), 22 + (map.teleporters[i].y * 9), temp);
|
||||
}
|
||||
else if(map.showtargets && map.explored[map.teleporters[i].x+(20*map.teleporters[i].y)]==0)
|
||||
else if(map.showtargets && map.isexplored(map.teleporters[i].x, map.teleporters[i].y))
|
||||
{
|
||||
int temp = 1126 + map.explored[map.teleporters[i].x + (20 * map.teleporters[i].y)];
|
||||
int temp = 1126 + (int) map.isexplored(map.teleporters[i].x, map.teleporters[i].y);
|
||||
if (graphics.flipmode) temp += 3;
|
||||
graphics.drawtile(40 + 3 + (map.teleporters[i].x * 12), 22 + (map.teleporters[i].y * 9), temp);
|
||||
}
|
||||
|
@ -2492,9 +2492,8 @@ void teleporterrender(void)
|
|||
{
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
if(map.explored[i+(j*20)]==0)
|
||||
if(!map.isexplored(i, j))
|
||||
{
|
||||
//graphics.drawfillrect(10 + (i * 12), 21 + (j * 9), 12, 9, 16, 16, 16);
|
||||
graphics.drawimage(2, 40 + (i * 12), 21 + (j * 9), false);
|
||||
}
|
||||
}
|
||||
|
@ -2525,15 +2524,15 @@ void teleporterrender(void)
|
|||
//draw legend details
|
||||
for (size_t i = 0; i < map.teleporters.size(); i++)
|
||||
{
|
||||
if (map.showteleporters && map.explored[map.teleporters[i].x + (20 * map.teleporters[i].y)] > 0)
|
||||
if (map.showteleporters && map.isexplored(map.teleporters[i].x, map.teleporters[i].y))
|
||||
{
|
||||
temp = 1126 + map.explored[map.teleporters[i].x + (20 * map.teleporters[i].y)];
|
||||
temp = 1126 + (int) map.isexplored(map.teleporters[i].x, map.teleporters[i].y);
|
||||
if (graphics.flipmode) temp += 3;
|
||||
graphics.drawtile(40 + 3 + (map.teleporters[i].x * 12), 22 + (map.teleporters[i].y * 9), temp);
|
||||
}
|
||||
else if(map.showtargets && map.explored[map.teleporters[i].x+(20*map.teleporters[i].y)]==0)
|
||||
else if(map.showtargets && map.isexplored(map.teleporters[i].x, map.teleporters[i].y))
|
||||
{
|
||||
temp = 1126 + map.explored[map.teleporters[i].x + (20 * map.teleporters[i].y)];
|
||||
temp = 1126 + (int) map.isexplored(map.teleporters[i].x, map.teleporters[i].y);
|
||||
if (graphics.flipmode) temp += 3;
|
||||
graphics.drawtile(40 + 3 + (map.teleporters[i].x * 12), 22 + (map.teleporters[i].y * 9), temp);
|
||||
}
|
||||
|
|
|
@ -1336,8 +1336,7 @@ void scriptclass::run(void)
|
|||
}
|
||||
else if (words[0] == "ifexplored")
|
||||
{
|
||||
int room = ss_toi(words[1]) + (20 * ss_toi(words[2]));
|
||||
if (INBOUNDS_ARR(room, map.explored) && map.explored[room] == 1)
|
||||
if (map.isexplored(ss_toi(words[1]), ss_toi(words[2])))
|
||||
{
|
||||
load(words[3]);
|
||||
position--;
|
||||
|
@ -1395,19 +1394,11 @@ void scriptclass::run(void)
|
|||
}
|
||||
else if (words[0] == "hidecoordinates")
|
||||
{
|
||||
int room = ss_toi(words[1]) + (20 * ss_toi(words[2]));
|
||||
if (INBOUNDS_ARR(room, map.explored))
|
||||
{
|
||||
map.explored[room] = false;
|
||||
}
|
||||
map.setexplored(ss_toi(words[1]), ss_toi(words[2]), false);
|
||||
}
|
||||
else if (words[0] == "showcoordinates")
|
||||
{
|
||||
int room = ss_toi(words[1]) + (20 * ss_toi(words[2]));
|
||||
if (INBOUNDS_ARR(room, map.explored))
|
||||
{
|
||||
map.explored[room] = true;
|
||||
}
|
||||
map.setexplored(ss_toi(words[1]), ss_toi(words[2]), true);
|
||||
}
|
||||
else if (words[0] == "hideship")
|
||||
{
|
||||
|
@ -1419,25 +1410,25 @@ void scriptclass::run(void)
|
|||
}
|
||||
else if (words[0] == "showsecretlab")
|
||||
{
|
||||
map.explored[16 + (20 * 5)] = 1;
|
||||
map.explored[17 + (20 * 5)] = 1;
|
||||
map.explored[18 + (20 * 5)] = 1;
|
||||
map.explored[17 + (20 * 6)] = 1;
|
||||
map.explored[18 + (20 * 6)] = 1;
|
||||
map.explored[19 + (20 * 6)] = 1;
|
||||
map.explored[19 + (20 * 7)] = 1;
|
||||
map.explored[19 + (20 * 8)] = 1;
|
||||
map.setexplored(16, 5, true);
|
||||
map.setexplored(17, 5, true);
|
||||
map.setexplored(18, 5, true);
|
||||
map.setexplored(17, 6, true);
|
||||
map.setexplored(18, 6, true);
|
||||
map.setexplored(19, 6, true);
|
||||
map.setexplored(19, 7, true);
|
||||
map.setexplored(19, 8, true);
|
||||
}
|
||||
else if (words[0] == "hidesecretlab")
|
||||
{
|
||||
map.explored[16 + (20 * 5)] = 0;
|
||||
map.explored[17 + (20 * 5)] = 0;
|
||||
map.explored[18 + (20 * 5)] = 0;
|
||||
map.explored[17 + (20 * 6)] = 0;
|
||||
map.explored[18 + (20 * 6)] = 0;
|
||||
map.explored[19 + (20 * 6)] = 0;
|
||||
map.explored[19 + (20 * 7)] = 0;
|
||||
map.explored[19 + (20 * 8)] = 0;
|
||||
map.setexplored(16, 5, false);
|
||||
map.setexplored(17, 5, false);
|
||||
map.setexplored(18, 5, false);
|
||||
map.setexplored(17, 6, false);
|
||||
map.setexplored(18, 6, false);
|
||||
map.setexplored(19, 6, false);
|
||||
map.setexplored(19, 7, false);
|
||||
map.setexplored(19, 8, false);
|
||||
}
|
||||
else if (words[0] == "showteleporters")
|
||||
{
|
||||
|
@ -2969,7 +2960,7 @@ void scriptclass::startgamemode( int t )
|
|||
obj.collect[j] = true;
|
||||
for (i = 0; i < 20; i++)
|
||||
{
|
||||
map.explored[i + (j * 20)] = 1;
|
||||
map.setexplored(i, j, true);
|
||||
}
|
||||
}
|
||||
game.insecretlab = true;
|
||||
|
|
Loading…
Reference in a new issue