private void RaycastCheck <TSetCellVisible>(GameFowManager pFowMgr, FowLos.CRaycastQuadrant quadrant, VInt2 newSurfPos, VInt3 unitLoc, int sightSqr, COM_PLAYERCAMP camp, bool bDrawDebugLines, byte inStartViewblockId, ref TSetCellVisible setCellVisible) where TSetCellVisible : ISetCellVisible { VInt2 aa = new VInt2(unitLoc.x, unitLoc.y); int x = quadrant.min.x; int x2 = quadrant.max.x; int y = quadrant.min.y; int y2 = quadrant.max.y; VInt2 zero = VInt2.zero; int halfSizeX = pFowMgr.m_halfSizeX; int halfSizeY = pFowMgr.m_halfSizeY; for (int i = x; i <= x2; i++) { for (int j = y; j <= y2; j++) { VInt2 vInt = new VInt2(i, j); if (i == newSurfPos.x && j == newSurfPos.y) { setCellVisible.SetVisible(vInt, camp, true); } else if ((vInt - newSurfPos).sqrMagnitude < sightSqr) { FieldObj.SViewBlockAttr sViewBlockAttr; if (!pFowMgr.m_pFieldObj.GrassBlockView && pFowMgr.m_pFieldObj.QueryAttr(vInt, out sViewBlockAttr) && sViewBlockAttr.BlockType == 1) { int num = (int)pFowMgr.m_pFieldObj.QueryViewblockId(vInt.x, vInt.y); if (num != (int)inStartViewblockId) { setCellVisible.SetVisible(vInt, camp, false); goto IL_6DD; } } VInt3 zero2 = VInt3.zero; pFowMgr.m_pFieldObj.LevelGrid.GridToWorldPos(i, j, out zero2); VInt2 vInt2 = new VInt2(zero2.x, zero2.y); VInt2 bb = vInt2; bb.x -= halfSizeX; bb.y -= halfSizeY; VInt2 bb2 = vInt2; bb2.x += halfSizeX; bb2.y -= halfSizeY; VInt2 bb3 = vInt2; bb3.x += halfSizeX; bb3.y += halfSizeY; VInt2 bb4 = vInt2; bb4.x -= halfSizeX; bb4.y += halfSizeY; FowLos.SGridWall sGridWall = default(FowLos.SGridWall); bool flag = false; bool flag2 = false; bool flag3 = false; bool flag4 = i < newSurfPos.x; bool flag5 = j < newSurfPos.y; int num2 = flag4 ? newSurfPos.x : (newSurfPos.x + 1); int num3 = flag5 ? newSurfPos.y : (newSurfPos.y + 1); int num4 = 0; while (!flag && (!flag2 || !flag3)) { if (!flag2) { int num5 = num2 + (flag4 ? (-num4) : num4); if (flag4 && num5 < i + 1) { flag2 = true; } else if (!flag4 && num5 > i) { flag2 = true; } if (!flag2 && quadrant.wallsVertical.Contains((byte)num5)) { List <FowLos.SBlockWalls> .Enumerator enumerator = quadrant.viewBlockArrayFinal.GetEnumerator(); while (enumerator.MoveNext() && !flag) { FowLos.SBlockWalls current = enumerator.get_Current(); List <FowLos.SGridWall> list = null; if (current.m_wallsVertical.TryGetValue((byte)num5, ref list)) { int count = list.get_Count(); int num6 = 0; while (num6 < count && !flag) { FowLos.SGridWall sGridWall2 = list.get_Item(num6); if (bDrawDebugLines) { if (FowLos.SegmentIntersect(aa, vInt2, sGridWall2.m_start, sGridWall2.m_end, ref zero)) { flag = true; } else if (FowLos.SegmentIntersect(aa, bb, sGridWall2.m_start, sGridWall2.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb2, sGridWall2.m_start, sGridWall2.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb3, sGridWall2.m_start, sGridWall2.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb4, sGridWall2.m_start, sGridWall2.m_end, ref zero)) { flag = true; } } else if (FowLos.SegmentIntersect(aa, vInt2, sGridWall2.m_start, sGridWall2.m_end)) { flag = true; } else if (FowLos.SegmentIntersect(aa, bb, sGridWall2.m_start, sGridWall2.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb2, sGridWall2.m_start, sGridWall2.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb3, sGridWall2.m_start, sGridWall2.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb4, sGridWall2.m_start, sGridWall2.m_end, ref zero)) { flag = true; } num6++; } } } } } if (!flag3 && !flag) { int num7 = num3 + (flag5 ? (-num4) : num4); if (flag5 && num7 < j + 1) { flag3 = true; } else if (!flag5 && num7 > j) { flag3 = true; } if (!flag3 && quadrant.wallsHorizontal.Contains((byte)num7)) { List <FowLos.SBlockWalls> .Enumerator enumerator2 = quadrant.viewBlockArrayFinal.GetEnumerator(); while (enumerator2.MoveNext() && !flag) { FowLos.SBlockWalls current2 = enumerator2.get_Current(); List <FowLos.SGridWall> list2 = null; if (current2.m_wallsHorizontal.TryGetValue((byte)num7, ref list2)) { int count2 = list2.get_Count(); int num8 = 0; while (num8 < count2 && !flag) { FowLos.SGridWall sGridWall3 = list2.get_Item(num8); if (bDrawDebugLines) { if (FowLos.SegmentIntersect(aa, vInt2, sGridWall3.m_start, sGridWall3.m_end, ref zero)) { flag = true; } else if (FowLos.SegmentIntersect(aa, bb, sGridWall3.m_start, sGridWall3.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb2, sGridWall3.m_start, sGridWall3.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb3, sGridWall3.m_start, sGridWall3.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb4, sGridWall3.m_start, sGridWall3.m_end, ref zero)) { flag = true; } } else if (FowLos.SegmentIntersect(aa, vInt2, sGridWall3.m_start, sGridWall3.m_end)) { flag = true; } else if (FowLos.SegmentIntersect(aa, bb, sGridWall3.m_start, sGridWall3.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb2, sGridWall3.m_start, sGridWall3.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb3, sGridWall3.m_start, sGridWall3.m_end, ref zero) || FowLos.SegmentIntersect(aa, bb4, sGridWall3.m_start, sGridWall3.m_end, ref zero)) { flag = true; } num8++; } } } } } num4++; } if (!flag) { setCellVisible.SetVisible(vInt, camp, true); } } IL_6DD :; } } }
public void ExploreCellsInternal <TSetCellVisible>(ref TSetCellVisible setCellVisible, VInt2 newSurfPos, VInt3 unitLoc, int surfSightRange, GameFowManager pFowMgr, COM_PLAYERCAMP camp, FowLos.EViewExploringMode ViewExploringMode, bool bDrawDebugLines) where TSetCellVisible : ISetCellVisible { if (pFowMgr == null || pFowMgr.m_pFieldObj == null) { return; } if (ViewExploringMode != FowLos.EViewExploringMode.EViewExploringMode_ShadowCast) { if (ViewExploringMode == FowLos.EViewExploringMode.EViewExploringMode_DistOnly) { for (int i = -surfSightRange - 1; i <= surfSightRange + 1; i++) { for (int j = -surfSightRange - 1; j <= surfSightRange + 1; j++) { VInt2 b = new VInt2(i, j); VInt2 inPos = newSurfPos + b; if (pFowMgr.IsInsideSurface(inPos.x, inPos.y) && b.sqrMagnitude < surfSightRange * surfSightRange) { setCellVisible.SetVisible(inPos, camp, true); } } } } else if (ViewExploringMode != FowLos.EViewExploringMode.EViewExploringMode_WatchTower && ViewExploringMode == FowLos.EViewExploringMode.EViewExploringMode_RayCast) { int sightSqr = surfSightRange * surfSightRange; int num = newSurfPos.x - surfSightRange; int num2 = newSurfPos.x + surfSightRange; int num3 = newSurfPos.y - surfSightRange; int num4 = newSurfPos.y + surfSightRange; num = Mathf.Clamp(num, 0, pFowMgr.m_pFieldObj.NumX - 1); num2 = Mathf.Clamp(num2, 0, pFowMgr.m_pFieldObj.NumX - 1); num3 = Mathf.Clamp(num3, 0, pFowMgr.m_pFieldObj.NumY - 1); num4 = Mathf.Clamp(num4, 0, pFowMgr.m_pFieldObj.NumY - 1); byte viewBlockId = pFowMgr.m_pFieldObj.LevelGrid.GetGridCell(newSurfPos).m_viewBlockId; FieldObj.SViewBlockAttr sViewBlockAttr = default(FieldObj.SViewBlockAttr); pFowMgr.m_pFieldObj.QueryAttr(newSurfPos, out sViewBlockAttr); FowLos.CRaycastQuadrant cRaycastQuadrant = new FowLos.CRaycastQuadrant(); cRaycastQuadrant.min = new VInt2(num, num3); cRaycastQuadrant.max = new VInt2(num2, num4); if (pFowMgr.m_pFieldObj.ViewBlockArrayImpl != null) { List <FowLos.SBlockWalls> .Enumerator enumerator = pFowMgr.m_pFieldObj.ViewBlockArrayImpl.GetEnumerator(); while (enumerator.MoveNext()) { FowLos.SBlockWalls current = enumerator.get_Current(); int areaId = (int)current.m_areaId; DebugHelper.Assert(areaId != 0); FieldObj.SViewBlockAttr sViewBlockAttr2; if (((int)viewBlockId != areaId || sViewBlockAttr.BlockType != 1) && (pFowMgr.m_pFieldObj.GrassBlockView || !pFowMgr.m_pFieldObj.ViewBlockAttrMap.TryGetValue((byte)areaId, ref sViewBlockAttr2) || sViewBlockAttr2.BlockType != 1) && this.ValidateViewBlock(current, cRaycastQuadrant.min.x, cRaycastQuadrant.max.x, cRaycastQuadrant.min.y, cRaycastQuadrant.max.y)) { cRaycastQuadrant.viewBlockArrayFinal.Add(current); Dictionary <byte, List <FowLos.SGridWall> > .Enumerator enumerator2 = current.m_wallsHorizontal.GetEnumerator(); while (enumerator2.MoveNext()) { List <byte> wallsHorizontal = cRaycastQuadrant.wallsHorizontal; KeyValuePair <byte, List <FowLos.SGridWall> > current2 = enumerator2.get_Current(); BaseAlgorithm.AddUniqueItem <byte>(wallsHorizontal, current2.get_Key()); } enumerator2 = current.m_wallsVertical.GetEnumerator(); while (enumerator2.MoveNext()) { List <byte> wallsVertical = cRaycastQuadrant.wallsVertical; KeyValuePair <byte, List <FowLos.SGridWall> > current3 = enumerator2.get_Current(); BaseAlgorithm.AddUniqueItem <byte>(wallsVertical, current3.get_Key()); } } } this.RaycastCheck <TSetCellVisible>(pFowMgr, cRaycastQuadrant, newSurfPos, unitLoc, sightSqr, camp, bDrawDebugLines, viewBlockId, ref setCellVisible); } cRaycastQuadrant.Clear(); } } }
private bool ValidateViewBlock(FowLos.SBlockWalls inBlockWalls, byte xMin, byte xMax, byte yMin, byte yMax) { return(inBlockWalls.m_xMin <= xMax && inBlockWalls.m_xMax >= xMin && inBlockWalls.m_yMin <= yMax && inBlockWalls.m_yMax >= yMin); }
private bool ValidateViewBlock(FowLos.SBlockWalls inBlockWalls, int xMin, int xMax, int yMin, int yMax) { return((int)inBlockWalls.m_xMin <= xMax && (int)inBlockWalls.m_xMax >= xMin && (int)inBlockWalls.m_yMin <= yMax && (int)inBlockWalls.m_yMax >= yMin); }
private List <FowLos.SBlockWalls> CreateBlockWallsInternal() { List <FowLos.SBlockWalls> list = new List <FowLos.SBlockWalls>(); Dictionary <byte, FowLos.SBlockContext> dictionary = this.CreateBlockMap(); Dictionary <byte, FowLos.SBlockContext> .Enumerator enumerator = dictionary.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair <byte, FowLos.SBlockContext> current = enumerator.get_Current(); FowLos.SBlockContext value = current.get_Value(); KeyValuePair <byte, FowLos.SBlockContext> current2 = enumerator.get_Current(); byte key = current2.get_Key(); FowLos.SBlockWalls sBlockWalls = default(FowLos.SBlockWalls); sBlockWalls.ParamlessConstruct(); sBlockWalls.m_areaId = key; sBlockWalls.m_xMin = value.m_xMin; sBlockWalls.m_xMax = value.m_xMax; sBlockWalls.m_yMin = value.m_yMin; sBlockWalls.m_yMax = value.m_yMax; KeyValuePair <byte, FowLos.SBlockContext> current3 = enumerator.get_Current(); List <FowLos.SPolylineSegment> polylineSegList = current3.get_Value().m_polylineSegList; int count = polylineSegList.get_Count(); for (int i = 0; i < count; i++) { FowLos.SGridWall sGridWall = default(FowLos.SGridWall); sGridWall.m_start = polylineSegList.get_Item(i).m_start; sGridWall.m_end = polylineSegList.get_Item(i).m_end; DebugHelper.Assert(sGridWall.m_start != sGridWall.m_end); if (sGridWall.m_start.x == sGridWall.m_end.x) { sGridWall.m_horizontal = false; byte b = (byte)((sGridWall.m_start.x + this.PaneX / 2 - this.LevelGrid.GridInfo.GridPos.x) / this.PaneX); DebugHelper.Assert(b >= 0); DebugHelper.Assert((int)b <= this.NumX); if (sGridWall.m_start.y > sGridWall.m_end.y) { sGridWall.m_start.y = sGridWall.m_start.y + 10; sGridWall.m_end.y = sGridWall.m_end.y - 10; } else { DebugHelper.Assert(sGridWall.m_start.y < sGridWall.m_end.y); sGridWall.m_start.y = sGridWall.m_start.y - 10; sGridWall.m_end.y = sGridWall.m_end.y + 10; } List <FowLos.SGridWall> list2 = null; if (sBlockWalls.m_wallsVertical.TryGetValue(b, ref list2)) { sBlockWalls.m_wallsVertical.get_Item(b).Add(sGridWall); } else { list2 = new List <FowLos.SGridWall>(); list2.Add(sGridWall); sBlockWalls.m_wallsVertical.Add(b, list2); } } else { DebugHelper.Assert(sGridWall.m_start.y == sGridWall.m_end.y); sGridWall.m_horizontal = true; byte b2 = (byte)((sGridWall.m_start.y + this.PaneY / 2 - this.LevelGrid.GridInfo.GridPos.y) / this.PaneY); DebugHelper.Assert(b2 >= 0); DebugHelper.Assert((int)b2 <= this.NumY); if (sGridWall.m_start.x > sGridWall.m_end.x) { sGridWall.m_start.x = sGridWall.m_start.x + 10; sGridWall.m_end.x = sGridWall.m_end.x - 10; } else { DebugHelper.Assert(sGridWall.m_start.x < sGridWall.m_end.x); sGridWall.m_start.x = sGridWall.m_start.x - 10; sGridWall.m_end.x = sGridWall.m_end.x + 10; } List <FowLos.SGridWall> list3 = null; if (sBlockWalls.m_wallsHorizontal.TryGetValue(b2, ref list3)) { sBlockWalls.m_wallsHorizontal.get_Item(b2).Add(sGridWall); } else { list3 = new List <FowLos.SGridWall>(); list3.Add(sGridWall); sBlockWalls.m_wallsHorizontal.Add(b2, list3); } } } list.Add(sBlockWalls); } return(list); }