Пример #1
0
        static void CycleRequest_Implementation(MyEntityCyclingOrder order, bool reset, bool findLarger, float metricValue, long currentEntityId, CyclingOptions options)
        {
            if (reset)
            {
                metricValue     = float.MinValue;
                currentEntityId = 0;
                findLarger      = false;
            }

            MyEntityCycling.FindNext(order, ref metricValue, ref currentEntityId, findLarger, options);

            var      e   = MyEntities.GetEntityByIdOrDefault(currentEntityId);
            Vector3D pos = e != null ? e.WorldMatrix.Translation : Vector3D.Zero;

            if (MyEventContext.Current.IsLocallyInvoked)
            {
                Cycle_Implementation(metricValue, currentEntityId, pos);
            }
            else
            {
                var proxy = e as IMyEventProxy;
                if (proxy != null)
                {
                    if (proxy is MyCubeGrid && (proxy as MyCubeGrid).Physics == null)
                    {
                        //don't send grids without physics
                    }
                    else
                    {
                        MyMultiplayer.ReplicateImmediatelly(proxy, MyEventContext.Current.Sender);
                    }
                }
                MyMultiplayer.RaiseStaticEvent(x => Cycle_Implementation, metricValue, currentEntityId, pos, MyEventContext.Current.Sender);
            }
        }
Пример #2
0
        public static float GetMetric(MyEntityCyclingOrder order, MyEntity entity)
        {
            var grid = entity as MyCubeGrid;
            var phys = entity.Physics;

            switch (order)
            {
            case MyEntityCyclingOrder.Characters: return(entity is MyCharacter ? 1 : 0);

            case MyEntityCyclingOrder.BiggestGrids: return(grid != null?grid.GetBlocks().Count : 0);

            case MyEntityCyclingOrder.Fastest: return(phys != null ? (float)Math.Round(phys.LinearVelocity.Length(), 2) : 0);

            case MyEntityCyclingOrder.BiggestDistanceFromPlayers: return((entity is MyVoxelBase) ? 0 : GetPlayerDistance(entity));

            case MyEntityCyclingOrder.MostActiveDrills: return(GetActiveBlockCount <MyShipDrill>(grid));

            case MyEntityCyclingOrder.MostActiveProductionBuildings: return(GetActiveBlockCount <MyProductionBlock>(grid));

            case MyEntityCyclingOrder.MostActiveReactors: return(GetActiveBlockCount <MyReactor>(grid));

            case MyEntityCyclingOrder.MostActiveSensors: return(GetActiveBlockCount <MySensorBlock>(grid));

            case MyEntityCyclingOrder.MostActiveThrusters: return(GetActiveBlockCount <MyThrust>(grid));

            case MyEntityCyclingOrder.MostWheels: return(GetActiveBlockCount <MyMotorSuspension>(grid, true));

            case MyEntityCyclingOrder.FloatingObjects: return(entity is MyFloatingObject ? 1 : 0);

            case MyEntityCyclingOrder.StaticObjects: return(entity.Physics != null && entity.Physics.AngularVelocity.AbsMax() < 0.05f && entity.Physics.LinearVelocity.AbsMax() < 0.05f ? 1:0);

            default: return(0);
            }
        }
Пример #3
0
        protected void OnOrderChanged(MyEntityCyclingOrder obj)
        {
            m_order = obj;
            UpdateSmallLargeGridSelection();
            UpdateCyclingAndDepower();

            OnCycleClicked(true, true);
        }
Пример #4
0
        static void CycleRequest_Implementation(MyEntityCyclingOrder order, bool reset, bool findLarger, float metricValue, long currentEntityId,CyclingOptions options)
        {
            if (reset)
            {
                metricValue = float.MinValue;
                currentEntityId = 0;
                findLarger = false;
            }

            MyEntityCycling.FindNext(order, ref metricValue, ref currentEntityId, findLarger, options);

            var e = MyEntities.GetEntityByIdOrDefault(currentEntityId);
            Vector3D pos = e != null ? e.WorldMatrix.Translation : Vector3D.Zero;

            if (MyEventContext.Current.IsLocallyInvoked)
            {
                Cycle_Implementation(metricValue, currentEntityId, pos);
            }
            else
            {
                var proxy = e as IMyEventProxy;
                if (proxy != null)
                {
                    if (proxy is MyCubeGrid && (proxy as MyCubeGrid).Physics == null)
                    {
                        //don't send grids without physics 
                    }
                    else
                    {
                        MyMultiplayer.ReplicateImmediatelly(proxy, MyEventContext.Current.Sender);
                    }
                }
                MyMultiplayer.RaiseStaticEvent(x => Cycle_Implementation, metricValue, currentEntityId, pos, MyEventContext.Current.Sender);
            }
        }
Пример #5
0
        protected void OnOrderChanged(MyEntityCyclingOrder obj)
        {
            m_order = obj;
            UpdateSmallLargeGridSelection();
            UpdateCyclingAndDepower();

            OnCycleClicked(true, true);
        }
Пример #6
0
        public static void FindNext(MyEntityCyclingOrder order, ref float metric, ref long entityId, bool findLarger, CyclingOptions options)
        {
            Metric current = new Metric()
            {
                Value = metric, EntityId = entityId
            };
            Metric start   = findLarger ? Metric.Max : Metric.Min;
            Metric result  = start;
            Metric extreme = start;

            foreach (var entity in MyEntities.GetEntities())
            {
                if (options.Enabled)
                {
                    MyCubeGrid grid = entity as MyCubeGrid;
                    if (options.OnlyLargeGrids && (grid == null || grid.GridSizeEnum != MyCubeSize.Large))
                    {
                        continue;
                    }

                    if (options.OnlySmallGrids && (grid == null || grid.GridSizeEnum != MyCubeSize.Small))
                    {
                        continue;
                    }
                }

                var newMetric = new Metric(GetMetric(order, entity), entity.EntityId);
                if (newMetric.Value == 0)
                {
                    continue;
                }

                if (findLarger)
                {
                    if (newMetric > current && newMetric < result)
                    {
                        result = newMetric;
                    }
                    if (newMetric < extreme)
                    {
                        extreme = newMetric;
                    }
                }
                else
                {
                    if (newMetric < current && newMetric > result)
                    {
                        result = newMetric;
                    }
                    if (newMetric > extreme)
                    {
                        extreme = newMetric;
                    }
                }
            }

            if (result == start)
            {
                result = extreme;
            }

            metric   = result.Value;
            entityId = result.EntityId;
        }
Пример #7
0
        public static void FindNext(MyEntityCyclingOrder order, ref float metric, ref long entityId, bool findLarger, CyclingOptions options)
        {
            Metric metric2 = new Metric {
                Value    = metric,
                EntityId = entityId
            };
            Metric metric3 = findLarger ? Metric.Max : Metric.Min;
            Metric metric4 = metric3;
            Metric metric5 = metric3;

            foreach (MyEntity entity in MyEntities.GetEntities())
            {
                if (options.Enabled)
                {
                    MyCubeGrid grid = entity as MyCubeGrid;
                    if (options.OnlyLargeGrids)
                    {
                        if (grid == null)
                        {
                            continue;
                        }
                        if (grid.GridSizeEnum != MyCubeSize.Large)
                        {
                            continue;
                        }
                    }
                    if (options.OnlySmallGrids && ((grid == null) || (grid.GridSizeEnum != MyCubeSize.Small)))
                    {
                        continue;
                    }
                }
                Metric metric7 = new Metric(GetMetric(order, entity), entity.EntityId);
                if (metric7.Value != 0f)
                {
                    if (findLarger)
                    {
                        if ((metric7 > metric2) && (metric7 < metric4))
                        {
                            metric4 = metric7;
                        }
                        if (metric7 < metric5)
                        {
                            metric5 = metric7;
                        }
                    }
                    else
                    {
                        if ((metric7 < metric2) && (metric7 > metric4))
                        {
                            metric4 = metric7;
                        }
                        if (metric7 > metric5)
                        {
                            metric5 = metric7;
                        }
                    }
                }
            }
            if (metric4 == metric3)
            {
                metric4 = metric5;
            }
            metric   = metric4.Value;
            entityId = metric4.EntityId;
        }
Пример #8
0
        public static float GetMetric(MyEntityCyclingOrder order, MyEntity entity)
        {
            MyCubeGrid             grid    = entity as MyCubeGrid;
            MyPhysicsComponentBase physics = entity.Physics;

            switch (order)
            {
            case MyEntityCyclingOrder.Characters:
                return((entity is MyCharacter) ? ((float)1) : ((float)0));

            case MyEntityCyclingOrder.BiggestGrids:
                return((grid != null) ? ((float)grid.GetBlocks().Count) : ((float)0));

            case MyEntityCyclingOrder.Fastest:
                if (physics == null)
                {
                    return(0f);
                }
                return((float)Math.Round((double)physics.LinearVelocity.Length(), 2));

            case MyEntityCyclingOrder.BiggestDistanceFromPlayers:
                if ((entity is MyVoxelBase) || (entity is MySafeZone))
                {
                    return(0f);
                }
                return(GetPlayerDistance(entity));

            case MyEntityCyclingOrder.MostActiveDrills:
                return(GetActiveBlockCount <MyShipDrill>(grid, false));

            case MyEntityCyclingOrder.MostActiveReactors:
                return(GetActiveBlockCount <MyReactor>(grid, false));

            case MyEntityCyclingOrder.MostActiveProductionBuildings:
                return(GetActiveBlockCount <MyProductionBlock>(grid, false));

            case MyEntityCyclingOrder.MostActiveSensors:
                return(GetActiveBlockCount <MySensorBlock>(grid, false));

            case MyEntityCyclingOrder.MostActiveThrusters:
                return(GetActiveBlockCount <MyThrust>(grid, false));

            case MyEntityCyclingOrder.MostWheels:
                return(GetActiveBlockCount <MyMotorSuspension>(grid, true));

            case MyEntityCyclingOrder.StaticObjects:
                int num1;
                if (((entity.Physics == null) || (entity.Physics.IsPhantom || (entity.Physics.AngularVelocity.AbsMax() >= 0.05f))) || (entity.Physics.LinearVelocity.AbsMax() >= 0.05f))
                {
                    num1 = 0;
                }
                else
                {
                    num1 = 1;
                }
                return((float)num1);

            case MyEntityCyclingOrder.FloatingObjects:
                return((entity is MyFloatingObject) ? ((float)1) : ((float)0));

            case MyEntityCyclingOrder.Planets:
                return((entity is MyPlanet) ? ((float)1) : ((float)0));

            case MyEntityCyclingOrder.OwnerLoginTime:
                return(GetOwnerLoginTime(grid));
            }
            return(0f);
        }