コード例 #1
0
        private void performSetup()
        {
            if (!setup)
            {
                setup = true;

                // Init sub-components.
                ThingCategory thingCategory = parent.def.category;

                compComponentsPositionTracker               = new CompComponentsPositionTracker();
                compComponentsPositionTracker.parent        = parent;
                compComponentsPositionTracker.mainComponent = this;

                compHiddenable               = new CompHiddenable();
                compHiddenable.parent        = parent;
                compHiddenable.mainComponent = this;

                compHideFromPlayer               = new CompHideFromPlayer();
                compHideFromPlayer.parent        = parent;
                compHideFromPlayer.mainComponent = this;

                if (thingCategory == ThingCategory.Building)
                {
                    compViewBlockerWatcher               = new CompViewBlockerWatcher();
                    compViewBlockerWatcher.parent        = parent;
                    compViewBlockerWatcher.mainComponent = this;
                }
                if (thingCategory == ThingCategory.Pawn ||
                    thingCategory == ThingCategory.Building)
                {
                    compFieldOfViewWatcher               = new CompFieldOfViewWatcher();
                    compFieldOfViewWatcher.parent        = parent;
                    compFieldOfViewWatcher.mainComponent = this;
                }
            }
        }
コード例 #2
0
        private static bool fovLineOfSight(IntVec3 sourceSq, IntVec3 targetLoc, Thing thing)
        {
            // If the thing is mannable, then use the manning pawn to perform the calculation.
            CompMannable compMannable = thing.TryGetComp <CompMannable>();

            if (compMannable != null)
            {
                thing = compMannable.ManningPawn;
                // Apply interaction cell offset.
                sourceSq += (thing.Position - thing.InteractionCell);
            }

            // If not a pawn, then doesn't need a fov calculation.
            if (!(thing is Pawn))
            {
                return(true);
            }

            MapComponentSeenFog    seenFog  = thing.Map.getMapComponentSeenFog();
            CompMainComponent      compMain = (CompMainComponent)thing.TryGetComp(CompMainComponent.COMP_DEF);
            CompFieldOfViewWatcher compFoV  = compMain.compFieldOfViewWatcher;
            // If requires moving, calculate only the base sight.
            int sightRange = Mathf.RoundToInt(compFoV.calcPawnSightRange(sourceSq, true, !thing.Position.AdjacentToCardinal(sourceSq)));

            if (!sourceSq.InHorDistOf(targetLoc, sightRange))
            {
                // If out of sightRange.
                return(false);
            }


            // Limit to needed octant.
            IntVec3 dir = targetLoc - sourceSq;

            byte octant;

            if (dir.x >= 0)
            {
                if (dir.z >= 0)
                {
                    if (dir.x >= dir.z)
                    {
                        octant = 0;
                    }
                    else
                    {
                        octant = 1;
                    }
                }
                else
                {
                    if (dir.x >= -dir.z)
                    {
                        octant = 7;
                    }
                    else
                    {
                        octant = 6;
                    }
                }
            }
            else
            {
                if (dir.z >= 0)
                {
                    if (-dir.x >= dir.z)
                    {
                        octant = 3;
                    }
                    else
                    {
                        octant = 2;
                    }
                }
                else
                {
                    if (-dir.x >= -dir.z)
                    {
                        octant = 4;
                    }
                    else
                    {
                        octant = 5;
                    }
                }
            }

            Map map = thing.Map;

            bool[] targetFound = new bool[1];
            ShadowCaster.computeFieldOfViewWithShadowCasting(sourceSq.x, sourceSq.z, sightRange,
                                                             seenFog.viewBlockerCells, map.Size.x, map.Size.z,
                                                             false, null, null, null,
                                                             targetFound, 0, 0, 0,
                                                             null, 0, 0, 0, 0, 0,
                                                             octant, targetLoc.x, targetLoc.z);
            return(targetFound[0]);
        }