J J
2012-08-09 07:05:24
Hello,
This snippets gets the room that you are in if there is a black outside and if the room is seperated. This is made for Dungeoneering, but should also work very well at Piramid Plunder and Stronghold of Security.
Works with angle compass angle.
Result w/ Debug:
Current room in green, other rooms are yellow.

The result of the function are all the points in the green area.
Takes around 650 ms to calculate, lape should push that down to around a tenth of that I hope.
This snippets gets the room that you are in if there is a black outside and if the room is seperated. This is made for Dungeoneering, but should also work very well at Piramid Plunder and Stronghold of Security.
function GetRoom(Debug: Boolean): TPointArray;
var
i, j, X, Y, nearest, room: Integer;
dist: Extended;
Rooms: T2DPointArray;
begin
for i:=MMX1 to MMX2 do
for j:=MMY1 to MMY2 do
begin
dist := Pow((MMCX-i), 2) + Pow((MMCY-j), 2);
if (dist < Pow(((MMX2-MMX1)/2), 2)) then
if not(FindColorTolerance(X, Y, 0, i, j, i, j, 10)) then
begin
SetLength(Result, Length(Result)+1);
Result[Length(Result)-1] := Point(i, j);
end;
end;
if Debug then
begin
for i:=0 to high(Result) do
SMART_DrawDot(False, Point(Result[i].x, Result[i].y+50), clYellow);
end;
nearest := 1000;
Rooms := SplitTPA(Result, 3);
if (Length(Rooms) > 0) then
for i := 0 to high(Rooms) do
begin
MiddleTPAEx(Rooms[i], X, Y)
dist := Abs(MMCX - X) + Abs(MMCY - Y);
if (dist < nearest) then
begin
nearest := Round(dist);
room := i;
end;
end;
SetLength(Result, Length(Rooms[room]));
Result := Rooms[room];
if Debug then
begin
for i:=0 to high(Result) do
SMART_DrawDot(False, Point(Result[i].x, Result[i].y+50), clGreen);
end;
end; Works with angle compass angle.
Result w/ Debug:
Current room in green, other rooms are yellow.

The result of the function are all the points in the green area.
Takes around 650 ms to calculate, lape should push that down to around a tenth of that I hope.