summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d354cd7)
raw | patch | inline | side by side (parent: d354cd7)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Wed, 23 Aug 2017 14:44:19 +0000 (17:44 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Wed, 23 Aug 2017 18:23:56 +0000 (21:23 +0300) |
src/game/g_grid.pas | patch | blob | history | |
src/game/g_holmes.inc | patch | blob | history | |
src/game/g_holmes.pas | patch | blob | history | |
src/game/g_player.pas | patch | blob | history |
diff --git a/src/game/g_grid.pas b/src/game/g_grid.pas
index c6fe09534a639f958ca7c300f354120d08a9eee7..27b553a30b26e98a9ad63dbfeb63aa2c890dee54 100644 (file)
--- a/src/game/g_grid.pas
+++ b/src/game/g_grid.pas
type TGridRayQueryCB = function (obj: ITP; tag: Integer; x, y, prevx, prevy: Integer): Boolean is nested; // return `true` to stop
type TGridAlongQueryCB = function (obj: ITP; tag: Integer): Boolean is nested; // return `true` to stop
+ type TCellQueryCB = procedure (x, y: Integer) is nested; // top-left cell corner coords
+
const TagDisabled = $40000000;
const TagFullMask = $3fffffff;
// trace line along the grid, calling `cb` for all objects in passed cells, in no particular order
function forEachAlongLine (x0, y0, x1, y1: Integer; cb: TGridAlongQueryCB; tagmask: Integer=-1; log: Boolean=false): ITP;
+ // debug
+ procedure forEachBodyCell (body: TBodyProxyId; cb: TCellQueryCB);
+ function forEachInCell (x, y: Integer; cb: TGridQueryCB): ITP;
procedure dumpStats ();
//WARNING! no sanity checks!
end;
+procedure TBodyGridBase.forEachBodyCell (body: TBodyProxyId; cb: TCellQueryCB);
+var
+ g, f, cidx: Integer;
+ cc: PGridCell;
+ //px: PBodyProxyRec;
+begin
+ if (body < 0) or (body > High(mProxies)) or not assigned(cb) then exit;
+ for g := 0 to High(mGrid) do
+ begin
+ cidx := mGrid[g];
+ while (cidx <> -1) do
+ begin
+ cc := @mCells[cidx];
+ for f := 0 to High(TGridCell.bodies) do
+ begin
+ if (cc.bodies[f] = -1) then break;
+ if (cc.bodies[f] = body) then cb((g mod mWidth)*mTileSize+mMinX, (g div mWidth)*mTileSize+mMinY);
+ //px := @mProxies[cc.bodies[f]];
+ end;
+ // next cell
+ cidx := cc.next;
+ end;
+ end;
+end;
+
+
+function TBodyGridBase.forEachInCell (x, y: Integer; cb: TGridQueryCB): ITP;
+var
+ f, cidx: Integer;
+ cc: PGridCell;
+begin
+ result := Default(ITP);
+ if not assigned(cb) then exit;
+ Dec(x, mMinX);
+ Dec(y, mMinY);
+ if (x < 0) or (y < 0) or (x >= mWidth*mTileSize) or (y > mHeight*mTileSize) then exit;
+ cidx := mGrid[(y div mTileSize)*mWidth+(x div mTileSize)];
+ while (cidx <> -1) do
+ begin
+ cc := @mCells[cidx];
+ for f := 0 to High(TGridCell.bodies) do
+ begin
+ if (cc.bodies[f] = -1) then break;
+ if cb(mProxies[cc.bodies[f]].mObj, mProxies[cc.bodies[f]].mTag) then begin result := mProxies[cc.bodies[f]].mObj; exit; end;
+ end;
+ // next cell
+ cidx := cc.next;
+ end;
+end;
+
+
// ////////////////////////////////////////////////////////////////////////// //
function TBodyGridBase.getGridWidthPx (): Integer; inline; begin result := mWidth*mTileSize; end;
function TBodyGridBase.getGridHeightPx (): Integer; inline; begin result := mHeight*mTileSize; end;
diff --git a/src/game/g_holmes.inc b/src/game/g_holmes.inc
index e3dd3804062e387e50ab515390ce367d26031214..d1265d06adfb2526d85a776cc8029573a420ec6f 100644 (file)
--- a/src/game/g_holmes.inc
+++ b/src/game/g_holmes.inc
glDisable(GL_TEXTURE_2D);
glColor4f(r/255.0, g/255.0, b/255.0, a/255.0);
+
glLineWidth(1);
+ glPointSize(1);
glBegin(GL_LINES);
glVertex2i(x1, y1);
end;
+procedure drawRect (x, y, w, h: Integer; r, g, b: Integer; a: Integer=255);
+begin
+ if (w < 0) or (h < 0) then exit;
+ if (w = 1) and (h = 1) then begin drawLine(x, y, x, y, r, g, b, a); exit; end;
+ Inc(w);
+ Inc(h);
+ drawLine(x, y, x+w-1, y, r, g, b, a);
+ drawLine(x+w-1, y+1, x+w-1, y+h-2, r, g, b, a);
+ drawLine(x+w-2, y+h-1, x, y+h-1, r, g, b, a);
+ drawLine(x, y+h-2, x, y+1, r, g, b, a);
+end;
+
+
// ////////////////////////////////////////////////////////////////////////// //
procedure shadeRect (x, y, w, h: Integer; a: Integer);
begin
diff --git a/src/game/g_holmes.pas b/src/game/g_holmes.pas
index 75e03bb30ec82a3a6509fc830fc790992a384103..d03d7b42840010d4b9ace73684791a7c494b4af3 100644 (file)
--- a/src/game/g_holmes.pas
+++ b/src/game/g_holmes.pas
//if pan.Enabled then g_Map_DisableWall(pan.arrIdx) else g_Map_EnableWall(pan.arrIdx);
end;
+ function monsInCell (mon: TMonster; tag: Integer): Boolean;
+ begin
+ result := false; // don't stop
+ e_WriteLog(Format('monster #%d (UID:%u) (proxyid:%d)', [mon.arrIdx, mon.UID, mon.proxyId]), MSG_NOTIFY);
+ end;
+
begin
//e_WriteLog(Format('mouse: x=%d; y=%d; but=%d; bstate=%d', [msx, msy, but, bstate]), MSG_NOTIFY);
if (gPlayer1 = nil) then exit;
if (ev.but = THMouseEvent.Left) then
begin
- mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
+ if ((kbS and THKeyEvent.ModShift) <> 0) then
+ begin
+ // dump monsters in cell
+ e_WriteLog('===========================', MSG_NOTIFY);
+ monsGrid.forEachInCell(pmsCurMapX, pmsCurMapY, monsInCell);
+ e_WriteLog('---------------------------', MSG_NOTIFY);
+ end
+ else
+ begin
+ // toggle wall
+ mapGrid.forEachAtPoint(pmsCurMapX, pmsCurMapY, wallToggle, (GridTagWall or GridTagDoor));
+ end;
exit;
end;
procedure plrDebugDraw ();
+ procedure drawTileGrid ();
+ var
+ x, y: Integer;
+ begin
+ y := mapGrid.gridY0;
+ while (y < mapGrid.gridY0+mapGrid.gridHeight) do
+ begin
+ x := mapGrid.gridX0;
+ while (x < mapGrid.gridX0+mapGrid.gridWidth) do
+ begin
+ if (x+mapGrid.tileSize > vpx) and (y+mapGrid.tileSize > vpy) and
+ (x < vpx+vpw) and (y < vpy+vph) then
+ begin
+ //e_DrawQuad(x, y, x+mapGrid.tileSize-1, y+mapGrid.tileSize-1, 96, 96, 96, 96);
+ drawRect(x, y, mapGrid.tileSize, mapGrid.tileSize, 96, 96, 96, 255);
+ end;
+ Inc(x, mapGrid.tileSize);
+ end;
+ Inc(y, mapGrid.tileSize);
+ end;
+ end;
+
+ procedure hilightCell (cx, cy: Integer);
+ begin
+ fillRect(cx, cy, monsGrid.tileSize, monsGrid.tileSize, 0, 128, 0, 64);
+ end;
+
function monsCollector (mon: TMonster; tag: Integer): Boolean;
var
ex, ey: Integer;
mon.getMapBox(mx, my, mw, mh);
//mx += mw div 2;
- //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
- shadeRect(mx-4, my-7*8-6, 110, 7*8+6, 128);
- my -= 8;
- my -= 2;
-
- // type
- drawText6(mx, my, Format('%s(U:%u)', [monsTypeToString(mon.MonsterType), mon.UID]), 255, 127, 0); my -= 8;
- // beh
- drawText6(mx, my, Format('Beh: %s', [monsBehToString(mon.MonsterBehaviour)]), 255, 127, 0); my -= 8;
- // state
- drawText6(mx, my, Format('State:%s (%d)', [monsStateToString(mon.MonsterState), mon.MonsterSleep]), 255, 127, 0); my -= 8;
- // health
- drawText6(mx, my, Format('Health:%d', [mon.MonsterHealth]), 255, 127, 0); my -= 8;
- // ammo
- drawText6(mx, my, Format('Ammo:%d', [mon.MonsterAmmo]), 255, 127, 0); my -= 8;
- // target
- drawText6(mx, my, Format('TgtUID:%u', [mon.MonsterTargetUID]), 255, 127, 0); my -= 8;
- drawText6(mx, my, Format('TgtTime:%d', [mon.MonsterTargetTime]), 255, 127, 0); my -= 8;
+ monsGrid.forEachBodyCell(mon.proxyId, hilightCell);
+
+ if ((kbS and THKeyEvent.ModCtrl) <> 0) then
+ begin
+ //fillRect(mx-4, my-7*8-6, 110, 7*8+6, 0, 0, 94, 250);
+ shadeRect(mx-4, my-7*8-6, 110, 7*8+6, 128);
+ my -= 8;
+ my -= 2;
+
+ // type
+ drawText6(mx, my, Format('%s(U:%u)', [monsTypeToString(mon.MonsterType), mon.UID]), 255, 127, 0); my -= 8;
+ // beh
+ drawText6(mx, my, Format('Beh: %s', [monsBehToString(mon.MonsterBehaviour)]), 255, 127, 0); my -= 8;
+ // state
+ drawText6(mx, my, Format('State:%s (%d)', [monsStateToString(mon.MonsterState), mon.MonsterSleep]), 255, 127, 0); my -= 8;
+ // health
+ drawText6(mx, my, Format('Health:%d', [mon.MonsterHealth]), 255, 127, 0); my -= 8;
+ // ammo
+ drawText6(mx, my, Format('Ammo:%d', [mon.MonsterAmmo]), 255, 127, 0); my -= 8;
+ // target
+ drawText6(mx, my, Format('TgtUID:%u', [mon.MonsterTargetUID]), 255, 127, 0); my -= 8;
+ drawText6(mx, my, Format('TgtTime:%d', [mon.MonsterTargetTime]), 255, 127, 0); my -= 8;
+
+ mon.getMapBox(mx, my, mw, mh);
+ end;
- mon.getMapBox(mx, my, mw, mh);
if (g_GetUIDType(mon.MonsterTargetUID) = UID_PLAYER) then
begin
eplr := g_Player_Get(mon.MonsterTargetUID);
glPushMatrix();
glTranslatef(-vpx, -vpy, 0);
+ drawTileGrid();
+
g_Mons_AlongLine(laserX0, laserY0, laserX1, laserY1, monsCollector, true);
if (monMarkedUID <> -1) then
end;
-{
- procedure drawTileGrid ();
- var
- x, y: Integer;
- begin
- y := mapGrid.gridY0;
- while (y < mapGrid.gridY0+mapGrid.gridHeight) do
- begin
- x := mapGrid.gridX0;
- while (x < mapGrid.gridX0+mapGrid.gridWidth) do
- begin
- if (x+mapGrid.tileSize > vpx) and (y+mapGrid.tileSize > vpy) and
- (x < vpx+vpw) and (y < vpy+vph) then
- begin
- e_DrawQuad(x, y, x+mapGrid.tileSize-1, y+mapGrid.tileSize-1, 96, 96, 96, 96);
- end;
- Inc(x, mapGrid.tileSize);
- end;
- Inc(y, mapGrid.tileSize);
- end;
- end;
-}
-
-
// ////////////////////////////////////////////////////////////////////////// //
function g_Holmes_mouseEvent (var ev: THMouseEvent): Boolean;
begin
diff --git a/src/game/g_player.pas b/src/game/g_player.pas
index e72a75689012b6f2e44462e0cfd5e327f0fa2c55..92aec4017d01675a83b8b37ad0aa4a98772bf619 100644 (file)
--- a/src/game/g_player.pas
+++ b/src/game/g_player.pas
procedure TPlayer.DrawAim();
procedure drawCast (sz: Integer; ax0, ay0, ax1, ay1: Integer);
+ {
procedure drawTileGrid ();
var
x, y: Integer;
Inc(y, mapGrid.tileSize);
end;
end;
+ }
var
ex, ey: Integer;
e_DrawLine(sz, ax0, ay0, ex, ey, 0, 0, 255, 96);
end;
- drawTileGrid();
+ //drawTileGrid();
end;
var