예제 #1
0
    private bool CheckLoSBetweenEdges(int origEdge, int destEdge)
    {
        Vector2 origEdgeVec = m_orig.CalcEdgeToScenePos(origEdge);
        Vector2 destEdgeVec = m_dest.CalcEdgeToScenePos(destEdge);

        for (int i = 0; i < m_hexagons.Count; i++)
        {
            // Check only if the hex is different from orig and dest and can block LoS.
            if (m_hexagons[i] != m_orig && m_hexagons[i] != m_dest && m_hexagons[i].BlocksLoS() &&
                IsBetween(origEdgeVec, destEdgeVec, m_hexagons[i].CalcCenterToScenePos()))
            {
                // Check if the edge point is between the segment of the line.
                bool isBetween = false;
                for (int j = 0; j < m_kEdgeCount && !isBetween; j++)
                {
                    isBetween = IsBetween(origEdgeVec, destEdgeVec, m_hexagons[i].CalcEdgeToScenePos(j));
                }

                // Check if this hex has points in both sides of the line.
                if (isBetween)
                {
                    int leftCount  = 0;
                    int rightCount = 0;

                    for (int j = 0; j < m_kEdgeCount; j++)
                    {
                        Vector2 currentHexEdgeVec = m_hexagons[i].CalcEdgeToScenePos(j);

                        // Don't compare if the position is the same!
                        if (currentHexEdgeVec != destEdgeVec && currentHexEdgeVec != origEdgeVec)
                        {
                            double d = (currentHexEdgeVec.x - origEdgeVec.x) * (destEdgeVec.y - origEdgeVec.y)
                                       - (currentHexEdgeVec.y - origEdgeVec.y) * (destEdgeVec.x - origEdgeVec.x);

                            if (d < -m_kMinDistLoS)
                            {
                                leftCount++;
                            }
                            else if (d > m_kMinDistLoS)
                            {
                                rightCount++;
                            }
                        }
                    }

                    // If this hex has points each side of the line, then it's blocking the LoS.
                    if (leftCount > 0 && rightCount > 0)
                    {
                        return(true);
                    }

                    // #CRIS TODO: if it's all left or all right, we need to check if there's an adjacent block in the inverse case, as a hotfix for the "special case"
                    if (leftCount > 0 && rightCount == 0)
                    {
                        //Debug.LogWarning("TODO CHECK");
                    }
                    else if (rightCount > 0 && leftCount == 0)
                    {
                        //Debug.LogWarning("TODO CHECK");
                    }
                }
            }
        }

        return(false);
    }