示例#1
0
        /// <summary>
        /// Determines if there is an obstruction between radar and target.
        /// </summary>
        private bool Obstructed(IMyEntity target, float range)
        {
            //Log.DebugLog("me: " + Entity.getBestName() + ", target: " + target.getBestName(), "Obstructed()");

            if (!myDefinition.LineOfSight)
            {
                return(false);
            }

            GetNearby(range);

            obstructed_ignore.Clear();
            obstructed_ignore.Add(Entity);
            obstructed_ignore.Add(target);

            return(RayCast.Obstructed(new LineD(Entity.GetCentre(), target.GetCentre()), m_nearbyEntities, obstructed_ignore));
        }
示例#2
0
文件: Projector.cs 项目: zrisher/ARMS
        /// <summary>
        /// Check opts, load/unload
        /// </summary>
        public void Update100()
        {
            if (m_holoEntities.Count != 0 && DateTime.UtcNow >= m_clearAllAt)
            {
                Log.DebugLog("clearing all holo entities");
                foreach (SeenHolo sh in m_holoEntities.Values)
                {
                    Log.DebugLog("removing " + sh.Seen.Entity.EntityId + "from m_holoEntities (clear all)");
                    OnRemove(sh);
                }
                m_holoEntities.Clear();
            }

            if (!Enabled)
            {
                return;
            }

            Vector3D playerPos = MyAPIGateway.Session.Player.GetPosition(), holoCentre = m_offset.ToWorld(m_block);
            double   distSquared = Vector3D.DistanceSquared(playerPos, holoCentre);

            m_playerCanSee = distSquared <= 1e4d;
            if (m_playerCanSee && distSquared > 100d)
            {
                List <MyLineSegmentOverlapResult <MyEntity> > entitiesInRay = ResourcePool <List <MyLineSegmentOverlapResult <MyEntity> > > .Get();

                m_playerCanSee = false;
                MyEntity[] ignore = new MyEntity[] { (MyEntity)MyAPIGateway.Session.Player.Controller.ControlledEntity };
                foreach (Vector3 vector in Static.Directions)
                {
                    LineD ray = new LineD(playerPos, holoCentre + vector * m_radiusHolo);
                    MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref ray, entitiesInRay);
                    if (!RayCast.Obstructed(ray, entitiesInRay.Select(overlap => overlap.Element), ignore))
                    {
                        m_playerCanSee = true;
                        entitiesInRay.Clear();
                        break;
                    }
                    entitiesInRay.Clear();
                }

                ResourcePool <List <MyLineSegmentOverlapResult <MyEntity> > > .Return(entitiesInRay);
            }

            if (!m_playerCanSee)
            {
                return;
            }

            RelayStorage storage = m_netClient.GetStorage();

            if (storage == null)
            {
                ((IMyTerminalBlock)m_block).AppendCustomInfo("No network connection");
                return;
            }

            m_clearAllAt = DateTime.UtcNow + Static.keepInCache;

            storage.ForEachLastSeen(CreateHolo);

            foreach (SeenHolo sh in m_holoEntities.Values)
            {
                if (CanDisplay(sh.Seen))
                {
                    if (!sh.Holo.Render.Visible)
                    {
                        Log.DebugLog("showing holo: " + sh.Seen.Entity.getBestName());
                        SetupProjection(sh.Holo);
                        SetVisible(sh.Holo, true);
                    }
                    if (sh.Seen.Entity is MyCubeGrid && sh.ColouredByIntegrity != ((m_options & Option.IntegrityColours) != 0))
                    {
                        if (sh.ColouredByIntegrity)
                        {
                            RestoreColour(sh);
                        }
                        else
                        {
                            ColourByIntegrity(sh);
                        }
                    }
                }
                else if (sh.Holo.Render.Visible)
                {
                    Log.DebugLog("hiding holo: " + sh.Seen.Entity.getBestName());
                    SetVisible(sh.Holo, false);
                }
            }

            if (m_holoEntitiesRemove.Count != 0)
            {
                foreach (long entityId in m_holoEntitiesRemove)
                {
                    Log.DebugLog("removing " + entityId + "from m_holoEntities");
                    SeenHolo sh;
                    if (!m_holoEntities.TryGetValue(entityId, out sh))
                    {
                        // this may be normal
                        Log.DebugLog("not in m_holoEntities: " + entityId, Logger.severity.WARNING);
                        continue;
                    }
                    OnRemove(sh);
                    m_holoEntities.Remove(entityId);
                }
                m_holoEntitiesRemove.Clear();
            }
        }