Ejemplo n.º 1
0
        protected void RefreshOctant(int2 origin, int radius, int octant, List <int> rowTilesInsideRadius)
        {
            ShadowLine     line       = new ShadowLine();
            bool           fullShadow = false;
            TileMap <Cell> map        = mapManager.Map;
            int            extents    = radius + 2;

            for (int row = 1; row < extents; row++)
            {
                int2 pos = origin + TransformOctant(row, 0, octant);

                if (!map.Bounds.Contains(pos))
                {
                    break;
                }

                for (int col = 0; col <= row; col++)
                {
                    pos = origin + TransformOctant(row, col, octant);

                    if (!map.Bounds.Contains(pos))
                    {
                        break;
                    }

                    Cell cell = map[pos];

                    if (cell != null)
                    {
                        if (fullShadow)
                        {
                            cell.RefreshVisibility(false);
                        }
                        else
                        {
                            Shadow projection     = ProjectTile(row, col);
                            bool   isInsideRadius = row <= rowTilesInsideRadius.Count && rowTilesInsideRadius[row - 1] > col;
                            bool   visible        = !line.IsInShadow(projection) && isInsideRadius;
                            cell.RefreshVisibility(visible);

                            if (visible && map[pos].BreaksLineOfSight())
                            {
                                line.Add(projection);
                                fullShadow = line.IsFullShadow;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Add(Shadow shadow)
        {
            int index = 0;

            for (; index < shadows.Count; index++)
            {
                if (shadows[index].Start >= shadow.Start)
                {
                    break;
                }
            }

            Shadow overlapingPrevious = null;

            if (index > 0 && shadows[index - 1].End > shadow.Start)
            {
                overlapingPrevious = shadows[index - 1];
            }

            Shadow overlapingNext = null;

            if (index < shadows.Count && shadows[index].Start < shadow.End)
            {
                overlapingNext = shadows[index];
            }

            if (overlapingNext != null)
            {
                if (overlapingPrevious != null)
                {
                    overlapingPrevious.End = overlapingNext.End;
                    shadows.RemoveAt(index);
                }
                else
                {
                    overlapingNext.Start = shadow.Start;
                }
            }
            else
            {
                if (overlapingPrevious != null)
                {
                    overlapingPrevious.End = shadow.End;
                }
                else
                {
                    shadows.Insert(index, shadow);
                }
            }
        }