Example #1
0
        private void DrawDisabledGuns()
        {
            if (Tick600 || Tick60 && QuickDisableGunsCheck)
            {
                QuickDisableGunsCheck         = false;
                _nearbyGridsTestSphere.Center = CameraPos;
                _gridsNearCamera.Clear();
                _uninitializedBlocks.Clear();

                MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref _nearbyGridsTestSphere, _gridsNearCamera);
                for (int i = _gridsNearCamera.Count - 1; i >= 0; i--)
                {
                    var grid = _gridsNearCamera[i] as MyCubeGrid;
                    if (grid?.Physics != null && !grid.MarkedForClose && !grid.IsPreview && !grid.Physics.IsPhantom)
                    {
                        var fatBlocks = grid.GetFatBlocks();
                        for (int j = 0; j < fatBlocks.Count; j++)
                        {
                            var block = fatBlocks[j];
                            if (block.IsFunctional && WeaponPlatforms.ContainsKey(block.BlockDefinition.Id))
                            {
                                GridAi gridAi;
                                if (!GridTargetingAIs.TryGetValue(block.CubeGrid, out gridAi) || !gridAi.WeaponBase.ContainsKey(block))
                                {
                                    _uninitializedBlocks.Add(block);
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < _uninitializedBlocks.Count; i++)
            {
                var badBlock = _uninitializedBlocks[i];
                if (badBlock.InScene)
                {
                    var lookSphere = new BoundingSphereD(badBlock.PositionComp.WorldAABB.Center, 30f);
                    if (Camera.IsInFrustum(ref lookSphere))
                    {
                        MyOrientedBoundingBoxD blockBox;
                        SUtils.GetBlockOrientedBoundingBox(badBlock, out blockBox);
                        DsDebugDraw.DrawBox(blockBox, _uninitializedColor);
                    }
                }
            }
        }
        private bool CompRestricted(CoreComponent comp)
        {
            var grid = comp.MyCube?.CubeGrid;

            GridAi ai;

            if (grid == null || !GridTargetingAIs.TryGetValue(grid, out ai))
            {
                return(false);
            }

            MyOrientedBoundingBoxD b;
            BoundingSphereD        s;
            MyOrientedBoundingBoxD blockBox;

            SUtils.GetBlockOrientedBoundingBox(comp.MyCube, out blockBox);

            if (IsWeaponAreaRestricted(comp.MyCube.BlockDefinition.Id.SubtypeId, blockBox, grid, comp.MyCube.EntityId, ai, out b, out s))
            {
                if (!DedicatedServer)
                {
                    if (comp.MyCube.OwnerId == PlayerId)
                    {
                        MyAPIGateway.Utilities.ShowNotification($"Block {comp.MyCube.DisplayNameText} was placed too close to another gun", 10000);
                    }
                }

                if (IsServer)
                {
                    comp.MyCube.CubeGrid.RemoveBlock(comp.MyCube.SlimBlock);
                }
                return(true);
            }

            return(false);
        }
Example #3
0
        private void UpdatePlacer()
        {
            if (!Placer.Visible)
            {
                Placer = null;
            }
            if (!MyCubeBuilder.Static.DynamicMode && MyCubeBuilder.Static.HitInfo.HasValue)
            {
                var    hit  = MyCubeBuilder.Static.HitInfo.Value as IHitInfo;
                var    grid = hit.HitEntity as MyCubeGrid;
                GridAi gridAi;
                if (grid != null && GridToMasterAi.TryGetValue(grid, out gridAi))
                {
                    if (MyCubeBuilder.Static.CurrentBlockDefinition != null)
                    {
                        var         subtypeIdHash = MyCubeBuilder.Static.CurrentBlockDefinition.Id.SubtypeId;
                        WeaponCount weaponCount;
                        if (gridAi.WeaponCounter.TryGetValue(subtypeIdHash, out weaponCount))
                        {
                            if (weaponCount.Max > 0 && gridAi.Construct.GetWeaponCount(subtypeIdHash) >= weaponCount.Max)
                            {
                                MyCubeBuilder.Static.NotifyPlacementUnable();
                                MyCubeBuilder.Static.Deactivate();
                                return;
                            }
                        }

                        if (WeaponAreaRestrictions.ContainsKey(subtypeIdHash))
                        {
                            MyOrientedBoundingBoxD restrictedBox;
                            MyOrientedBoundingBoxD buildBox = MyCubeBuilder.Static.GetBuildBoundingBox();
                            BoundingSphereD        restrictedSphere;
                            if (IsWeaponAreaRestricted(subtypeIdHash, buildBox, grid, 0, null, out restrictedBox, out restrictedSphere))
                            {
                                DsDebugDraw.DrawBox(buildBox, _uninitializedColor);
                            }

                            if (MyAPIGateway.Session.Config.HudState == 1)
                            {
                                if (restrictedBox.HalfExtent.AbsMax() > 0)
                                {
                                    DsDebugDraw.DrawBox(restrictedBox, _restrictionAreaColor);
                                }
                                if (restrictedSphere.Radius > 0)
                                {
                                    DsDebugDraw.DrawSphere(restrictedSphere, _restrictionAreaColor);
                                }
                                for (int i = 0; i < gridAi.Weapons.Count; i++)
                                {
                                    MyOrientedBoundingBoxD b;
                                    BoundingSphereD        s;
                                    CoreComponent          Comp = gridAi.Weapons[i];
                                    MyOrientedBoundingBoxD blockBox;
                                    SUtils.GetBlockOrientedBoundingBox(Comp.MyCube, out blockBox);

                                    CalculateRestrictedShapes(Comp.MyCube.BlockDefinition.Id.SubtypeId, blockBox, out b, out s);

                                    if (s.Radius > 0)
                                    {
                                        DsDebugDraw.DrawSphere(s, _restrictionAreaColor);
                                    }
                                    if (b.HalfExtent.AbsMax() > 0)
                                    {
                                        DsDebugDraw.DrawBox(b, _restrictionAreaColor);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        private void DrawDisabledGuns()
        {
            if (Tick600 || Tick60 && QuickDisableGunsCheck)
            {
                QuickDisableGunsCheck         = false;
                _nearbyGridsTestSphere.Center = CameraPos;
                _gridsNearCamera.Clear();
                _uninitializedBlocks.Clear();
                _debugBlocks.Clear();

                MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref _nearbyGridsTestSphere, _gridsNearCamera);
                for (int i = _gridsNearCamera.Count - 1; i >= 0; i--)
                {
                    var grid = _gridsNearCamera[i] as MyCubeGrid;
                    if (grid?.Physics != null && !grid.MarkedForClose && !grid.IsPreview && !grid.Physics.IsPhantom)
                    {
                        var fatBlocks = grid.GetFatBlocks();
                        for (int j = 0; j < fatBlocks.Count; j++)
                        {
                            var block = fatBlocks[j];
                            if (block.IsFunctional && WeaponPlatforms.ContainsKey(block.BlockDefinition.Id))
                            {
                                GridAi          gridAi;
                                WeaponComponent comp;
                                if (!GridTargetingAIs.TryGetValue(block.CubeGrid, out gridAi) || !gridAi.WeaponBase.TryGetValue(block, out comp))
                                {
                                    _uninitializedBlocks.Add(block);
                                }
                                else if (comp != null && comp.Data.Repo.Base.Set.Overrides.Debug)
                                {
                                    _debugBlocks.Add(comp);
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < _uninitializedBlocks.Count; i++)
            {
                var badBlock = _uninitializedBlocks[i];
                if (badBlock.InScene)
                {
                    var lookSphere = new BoundingSphereD(badBlock.PositionComp.WorldAABB.Center, 30f);
                    if (Camera.IsInFrustum(ref lookSphere))
                    {
                        MyOrientedBoundingBoxD blockBox;
                        SUtils.GetBlockOrientedBoundingBox(badBlock, out blockBox);
                        DsDebugDraw.DrawBox(blockBox, _uninitializedColor);
                    }
                }
            }

            for (int i = 0; i < _debugBlocks.Count; i++)
            {
                var comp = _debugBlocks[i];
                if (comp.MyCube.InScene)
                {
                    var lookSphere = new BoundingSphereD(comp.MyCube.PositionComp.WorldAABB.Center, 100f);

                    if (Camera.IsInFrustum(ref lookSphere))
                    {
                        foreach (var w in comp.Platform.Weapons)
                        {
                            if (!w.AiEnabled && w.ActiveAmmoDef.AmmoDef.Trajectory.Guidance == WeaponDefinition.AmmoDef.TrajectoryDef.GuidanceType.Smart)
                            {
                                w.SmartLosDebug();
                            }
                        }
                    }
                }
            }
        }