Пример #1
0
        private void updateGlowGrid()
        {
            //Log.Message("Angle: start update glow grid using cache");

            //this is why I wanted a list to and not an array, saves some valuable CPU overhead
            foreach (GlowGridCache cell in ColorCellIndexCache.Where(x => !x.IsBlocked))
            {
                Find.GlowGrid.glowGrid[cell.CellGridIndex] = cell.ColorAtCellIndex;
            }


            //for (int i = 0; i < ColorCellIndexCache.Count; i++)
            //{
            //    var pos = ColorCellIndexCache[i];
            //    Find.GlowGrid.glowGrid[pos.CellGridIndex] = pos.ColorAtCellIndex;

            //    //dont know if this is inneficeint or what but it works for long range lighting in this case
            //    //Find.MapDrawer.MapMeshDirty(pos.Position, MapMeshFlag.GroundGlow);
            //}

            //Log.Message("Anlge: updated glowgrid from cache");
            //Dont really want this here but the timing of this particulr object is weird so I need to mark it dirty

            //In this case we need to mark several positions as dirty as the internal updated works with regions only
            Find.MapDrawer.MapMeshDirty(Position, MapMeshFlag.GroundGlow);
        }
Пример #2
0
        private bool isBlocked(IntVec3 position, int angleDelta)
        {
            Thing thingBlockers = innerArray[CellIndices.CellToIndex(position)];

            if (thingBlockers != null)
            {
                if (thingBlockers.def.blockLight)
                {
                    //block this tile
                    addCellIndex(position, true);
                    //block next forward tile to prevent further light going this way
                    addCellIndex(position.TranslateDirection(Orientation), true);

                    //block next left and right tiles to prevent further light going this way and help with "angle" detection
                    addCellIndex(position.TranslateDirection(Orientation, 1), true);
                    addCellIndex(position.TranslateDirection(Orientation, -1), true);
                }
                thingBlockers = null;
                //Log.Message("Blocking by Def: X: " + position.x + " Z: " + position.z);
                return(true);
            }

            /////----------If def.blocked not found scan for previous blocks-------------//////


            //I pre emtifly block the cell at the building collision level so now I can find it here and carry on blocking
            //This part feels a bit iffy to me because I have to carry on calculation blockers. Not sure how flag any further
            //blockers in that particular direction to be forgotten about. possibly a shortfall in my calculation logic. Oh well..it works I suppose
            GlowGridCache thisCellBlocked = ColorCellIndexCache.FirstOrDefault(deltaZ => position == deltaZ.Position & deltaZ.IsBlocked);

            if (thisCellBlocked != null)
            {
                //block the next cell ahead and repeat el'kapitan!
                addCellIndex(thisCellBlocked.Position.TranslateDirection(Orientation), true);
                if (angleDelta < 0)
                {
                    //pffff.. a bit ugly i know.. but i need to compensate for wide angles over distance
                    addCellIndex(thisCellBlocked.Position.TranslateDirection(Orientation, -1), true);
                    //addCellIndex(thisCellBlocked.Position.TranslateDirection(this.Orientation, -2), true);
                    //addCellIndex(thisCellBlocked.Position.TranslateDirection(this.Orientation, -3), true);
                }
                if (angleDelta > 0)
                {
                    addCellIndex(thisCellBlocked.Position.TranslateDirection(Orientation, 1), true);
                    //addCellIndex(thisCellBlocked.Position.TranslateDirection(this.Orientation, 2), true);
                    //addCellIndex(thisCellBlocked.Position.TranslateDirection(this.Orientation, 3), true);
                }
            }



            return(false);
        }
Пример #3
0
        private void addCellIndex(IntVec3 position, bool isBlocked)
        {
            int _idx = position.AsCellIndex();

            //protect from multipoe entires of the same index. I know we can use an array but in this case we want an IEnumarable list
            if (!ColorCellIndexCache.Any(x => x.CellGridIndex == _idx))
            {
                ColorCellIndexCache.Add(new GlowGridCache
                {
                    Position         = position,
                    CellGridIndex    = _idx,
                    ColorAtCellIndex = isBlocked ? new Color32(0, 0, 0, 0) : Color,
                    IsBlocked        = isBlocked
                });
            }


            //Log.Message("ANGLE POS: " + position.ToLog());
        }