protected int GetTileBy(int x, int y, PluginManager manager, Func<int,bool> checker)
{
Map map = manager.GetActiveMap();
// g takes x/y, corrects for room wrapping, returns the tile to check
Func<int,int,int> g = (a,b) =>
{
int roomX = manager.GetMapSelectedX();
int roomY = manager.GetMapSelectedY();
int floor = manager.GetMapSelectedFloor();
if (a < 0) {
if (roomX == 0)
return -1;
roomX--;
a += map.RoomWidth;
}
else if (a >= map.RoomWidth) {
if (roomX == map.MapWidth-1)
return -1;
roomX++;
a -= map.RoomWidth;
}
if (b < 0) {
if (roomY == 0)
return -1;
roomY--;
b += map.RoomHeight;
}
else if (b >= map.RoomHeight) {
if (roomY == map.MapHeight-1)
return -1;
roomY++;
b -= map.RoomHeight;
}
return map.GetRoom(roomX,roomY,floor).GetTile(a,b);
};
Func<int,bool> fx = (a) => checker(g(a,y));
Func<int,bool> fy = (b) => checker(g(x,b));
int xi;
if (fx(x-1) && fx(x+1))
xi = 1;
else if (fx(x-1))
xi = 2;
else if (fx(x+1))
xi = 0;
else
xi = -1;
int yi;
if (fy(y-1) && fy(y+1))
yi = 1;
else if (fy(y-1))
yi = 2;
else if (fy(y+1))
yi = 0;
else
yi = -1;
if (xi == -1 && yi == -1)
return baseTiles[1,1];
if (xi == -1) {
return vTiles[yi == 2 ? 1 : 0];
}
else if (yi == -1) {
return hTiles[xi == 2 ? 1 : 0];
}
return baseTiles[yi,xi];
}