public bool Intersect(FloatRectangle rect) { if ( ((mX <= rect.mX && rect.mX <= mX+mWidth) || (rect.mX <= mX && mX <= rect.mX+rect.mWidth)) && ((mY <= rect.mY && rect.mY <=mY+mHeight) || (rect.mY <= mY && mY <= rect.mY+rect.mHeight)) ) return true; return false; }
/// <summary> /// Jan's proposal, don't know if it is faster than mine /// </summary> public void CalcAllVisibilities(List<IVisible> playerView, List<IVisible> computerView) { GameLogic gameLogic = GameLogic.GetInstance(); playerView.Clear(); computerView.Clear(); foreach (IGameObject unit in gameLogic.mObjectList) { if (unit is IVisible) ((IVisible)unit).GetVisibility().Reset(); } foreach (IGameObject unit in gameLogic.mObjectList) { if (unit is IVisible) { IVisible visible = (IVisible)unit; float radius = visible.LineOfSight + GlobalValues.GetInstance().mPlanetRadius[PlanetSize.Large]; FloatRectangle sightArea = new FloatRectangle(visible.Position, radius); if (visible.Allegiance == Allegiance.Player) { List<IQuadNodeReferring> candidates = gameLogic.SuperFogManager.PlayerFogManager.GetCandidatesInReach(sightArea); foreach (IQuadNodeReferring candidate in candidates) { PlayerFogManager.HandleSingleVisibility(visible, (IVisible) candidate, playerView); } } else if (visible.Allegiance == Allegiance.Computer) { List<IQuadNodeReferring> candidates = gameLogic.SuperFogManager.PcFogManager.GetCandidatesInReach(sightArea); foreach (IQuadNodeReferring candidate in candidates) { PcFogManager.HandleSingleVisibility(visible, (IVisible)candidate, computerView); } } } } }
public List<IQuadNodeReferring> GetCandidatesInReach(FloatRectangle area) { return Root.GetElemsFromCoveredNodes(area); }
public void Init() { mChild = new Dictionary<Orientation, QuadNode>(); mChild.Add(Orientation.LeftUpper, null); mChild.Add(Orientation.RightUpper, null); mChild.Add(Orientation.LeftLower, null); mChild.Add(Orientation.RightLower, null); if (mParent == null) mDepth = 0; else mDepth = mParent.mDepth + 1; mUnits = new List<IQuadNodeReferring>(); mArea = CalcArea(); }
public List<IQuadNodeReferring> GetElemsFromCoveredNodes(FloatRectangle area) { if (IsLeaf()) { return mUnits; } /*else*/ { List<IQuadNodeReferring> result = new List<IQuadNodeReferring>(); foreach (QuadNode child in mChild.Values) { if (area.Contains(child.mArea)) result.AddRange(child.GetRecursiveElems()); else if (child.mArea.Intersect(area)) result.AddRange(child.GetElemsFromCoveredNodes(area)); } return result; } }
public bool Contains(FloatRectangle area) { return (mX <= area.mX && mY <= area.mY && mX + mWidth >= area.mX + area.mWidth && mY + mHeight >= area.mY + area.mHeight); }