X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_map.pas;h=a73434b9b8c6632bd41dbe63a194dd5376885def;hb=6a553cae9dbb5171d17826cfd19dd0a0b7c0ed8c;hp=f063f74081e5cf554b813bf9ea1a950283d4cd74;hpb=58b15f7d5aee8dc280a2e407c11a1f0448eea7ef;p=d2df-sdl.git diff --git a/src/game/g_map.pas b/src/game/g_map.pas index f063f74..a73434b 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -172,6 +172,9 @@ var function panelTypeToTag (panelType: Word): Integer; // returns GridTagXXX +function g_Map_traceToNearestWall (x0, y0, x1, y1: Integer; hitx: PInteger=nil; hity: PInteger=nil): Integer; + + implementation uses @@ -281,6 +284,74 @@ begin end; +// wall index in `gWalls` or -1 +function g_Map_traceToNearestWall (x0, y0, x1, y1: Integer; hitx: PInteger=nil; hity: PInteger=nil): Integer; +var + maxDistSq: Single; + + function sqchecker (pan: TPanel; var ray: Ray2D): Single; + var + aabb: AABB2D; + tmin: Single; + begin + result := -666.0; // invalid + if not pan.Enabled then exit; + aabb := AABB2D.CreateWH(pan.X, pan.Y, pan.Width, pan.Height); + if not aabb.valid then exit; + if aabb.intersects(ray, @tmin) then + begin + //if (tmin*tmin > maxDistSq) then exit; + if (tmin >= 0.0) then + begin + //e_WriteLog(Format('sqchecker(%d,%d,%d,%d): panel #%d (%d,%d)-(%d,%d); tmin=%f', [x0, y0, x1, y1, pan.arrIdx, pan.X, pan.Y, pan.Width, pan.Height, tmin]), MSG_NOTIFY); + //if (tmin < 0.0) then tmin := 0.0; + result := tmin; + end; + end; + end; + +var + qr: TDynAABBTreeMap.TSegmentQueryResult; + ray: Ray2D; + hxf, hyf: Single; + hx, hy: Integer; +begin + result := -1; + if (mapTree = nil) then exit; + maxDistSq := (x1-x0)*(x1-x0)+(y1-y0)*(y1-y0); + if mapTree.segmentQuery(qr, x0, y0, x1, y1, sqchecker, (GridTagWall or GridTagDoor)) then + begin + if (qr.flesh <> nil) and (qr.time*qr.time <= maxDistSq) then + begin + result := qr.flesh.arrIdx; + if (hitx <> nil) or (hity <> nil) then + begin + ray := Ray2D.Create(x0, y0, x1, y1); + hxf := ray.origX+ray.dirX*qr.time; + hyf := ray.origY+ray.dirY*qr.time; + while true do + begin + hx := trunc(hxf); + hy := trunc(hyf); + if (hx >= qr.flesh.X) and (hy >= qr.flesh.Y) and (hx < qr.flesh.X+qr.flesh.Width) and (hy < qr.flesh.Y+qr.flesh.Height) then + begin + // go back a little + hxf -= ray.dirX; + hyf -= ray.dirY; + end + else + begin + break; + end; + end; + if (hitx <> nil) then hitx^ := hx; + if (hity <> nil) then hity^ := hy; + end; + end; + end; +end; + + function g_Map_IsSpecialTexture(Texture: String): Boolean; begin Result := (Texture = TEXTURE_NAME_WATER) or @@ -962,7 +1033,7 @@ end; procedure g_Map_ReAdd_DieTriggers(); - function monsDieTrig (monidx: Integer; mon: TMonster): Boolean; + function monsDieTrig (mon: TMonster): Boolean; var a: Integer; begin