DEADSOFTWARE

added common file with compiler flags; cosmetic fix in g_monsters.pas
[d2df-sdl.git] / src / game / g_grid.pas
index ffa05200c4d91b6957a186a6142ab6abe5d0ab1e..a56c670270a42aeb38439164b4c3a1160b1cee43 100644 (file)
@@ -13,8 +13,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *)
-{$MODE DELPHI}
-{$modeswitch nestedprocvars}
+{$INCLUDE g_amodes.inc}
 unit g_grid;
 
 interface
@@ -67,6 +66,7 @@ type
   TBodyGrid = class(TObject)
   private
     mTileSize: Integer;
+    mMinX, mMinY: Integer; // so grids can start at any origin
     mWidth, mHeight: Integer; // in tiles
     mGrid: array of Integer; // mWidth*mHeight, index in mCells
     mCells: array of TGridCell; // cell pool
@@ -90,7 +90,7 @@ type
     function forGridRect (x, y, w, h: Integer; cb: GridInternalCB): Boolean;
 
   public
-    constructor Create (aPixWidth, aPixHeight: Integer; aTileSize: Integer=GridDefaultTileSize);
+    constructor Create (aMinPixX, aMinPixY, aPixWidth, aPixHeight: Integer; aTileSize: Integer=GridDefaultTileSize);
     destructor Destroy (); override;
 
     function insertBody (aObj: TObject; ax, ay, aWidth, aHeight: Integer; aTag: Integer=0): TBodyProxy;
@@ -170,7 +170,7 @@ end;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
-constructor TBodyGrid.Create (aPixWidth, aPixHeight: Integer; aTileSize: Integer=GridDefaultTileSize);
+constructor TBodyGrid.Create (aMinPixX, aMinPixY, aPixWidth, aPixHeight: Integer; aTileSize: Integer=GridDefaultTileSize);
 var
   idx: Integer;
 begin
@@ -179,6 +179,8 @@ begin
   if aPixWidth < aTileSize then aPixWidth := aTileSize;
   if aPixHeight < aTileSize then aPixHeight := aTileSize;
   mTileSize := aTileSize;
+  mMinX := aMinPixX;
+  mMinY := aMinPixY;
   mWidth := (aPixWidth+aTileSize-1) div aTileSize;
   mHeight := (aPixHeight+aTileSize-1) div aTileSize;
   SetLength(mGrid, mWidth*mHeight);
@@ -334,6 +336,10 @@ var
 begin
   result := false;
   if (w < 1) or (h < 1) or not assigned(cb) then exit;
+  // fix coords
+  Dec(x, mMinX);
+  Dec(y, mMinY);
+  // go on
   if (x+w <= 0) or (y+h <= 0) then exit;
   if (x >= mWidth*mTileSize) or (y >= mHeight*mTileSize) then exit;
   for gy := y div mTileSize to (y+h-1) div mTileSize do