Exemplo n.º 1
0
        public override void UpdateBeforeSimulation()
        {
            try
            {
                if (SuppressWc)
                {
                    return;
                }

                if (DeformProtection.Count > 0 && Tick - LastDeform > 0)
                {
                    DeformProtection.Clear();
                }

                Timings();

                if (IsClient)
                {
                    if (ClientSideErrorPkt.Count > 0)
                    {
                        ReproccessClientErrorPackets();
                    }

                    if (ClientPacketsToClean.Count > 0)
                    {
                        CleanClientPackets();
                    }
                }

                if (IsServer)
                {
                    if (Tick60)
                    {
                        AcqManager.Observer();
                    }
                    if (Tick600)
                    {
                        AcqManager.ReorderSleep();
                    }
                }

                if (!DedicatedServer && TerminalMon.Active)
                {
                    TerminalMon.Monitor();
                }

                MyCubeBlock cube;
                if (Tick60 && UiInput.ControlKeyPressed && UiInput.CtrlPressed && GetAimedAtBlock(out cube) && cube.BlockDefinition != null && WeaponCoreBlockDefs.ContainsKey(cube.BlockDefinition.Id.SubtypeName))
                {
                    ProblemRep.GenerateReport(cube);
                }

                if (!IsClient && !InventoryUpdate && WeaponToPullAmmo.Count > 0 && ITask.IsComplete)
                {
                    StartAmmoTask();
                }

                if (!CompsToStart.IsEmpty)
                {
                    StartComps();
                }

                if (Tick120 && CompsDelayed.Count > 0)
                {
                    DelayedComps();
                }

                if (Tick20 && !DelayedAiClean.IsEmpty)
                {
                    DelayedAiCleanup();
                }

                if (CompReAdds.Count > 0)
                {
                    ChangeReAdds();
                }

                if (Tick3600 && MpActive)
                {
                    NetReport();
                }

                if (Tick180)
                {
                    ProfilePerformance();
                }

                FutureEvents.Tick(Tick);

                if (HomingWeapons.Count > 0)
                {
                    UpdateHomingWeapons();
                }


                if (MpActive)
                {
                    if (PacketsToClient.Count > 0 || PrunedPacketsToClient.Count > 0)
                    {
                        ProccessServerPacketsForClients();
                    }
                    if (PacketsToServer.Count > 0)
                    {
                        ProccessClientPacketsForServer();
                    }
                }
            }
            catch (Exception ex) { Log.Line($"Exception in SessionBeforeSim: {ex}"); }
        }
Exemplo n.º 2
0
        public bool IsWeaponAreaRestricted(MyStringHash subtype, MyOrientedBoundingBoxD cubeBoundingBox, MyCubeGrid myGrid, long ignoredEntity, GridAi gridAi, out MyOrientedBoundingBoxD restrictedBox, out BoundingSphereD restrictedSphere)
        {
            _tmpNearByBlocks.Clear();
            GridAi ai;

            if (gridAi == null)
            {
                if (!GridToMasterAi.ContainsKey(myGrid))
                {
                    restrictedSphere = new BoundingSphereD();
                    restrictedBox    = new MyOrientedBoundingBoxD();
                    return(false);
                }
                ai = GridToMasterAi[myGrid];
            }
            else
            {
                ai = gridAi;
            }

            CalculateRestrictedShapes(subtype, cubeBoundingBox, out restrictedBox, out restrictedSphere);
            var queryRadius = Math.Max(restrictedBox.HalfExtent.AbsMax(), restrictedSphere.Radius);

            if (queryRadius < 0.01)
            {
                return(false);
            }

            var restriction = WeaponAreaRestrictions[subtype];
            var checkBox    = restriction.RestrictionBoxInflation > 0;
            var checkSphere = restriction.RestrictionRadius > 0;
            var querySphere = new BoundingSphereD(cubeBoundingBox.Center, queryRadius);

            myGrid.Hierarchy.QuerySphere(ref querySphere, _tmpNearByBlocks);

            foreach (var grid in ai.SubGrids)
            {
                if (grid == myGrid || !GridTargetingAIs.ContainsKey(grid))
                {
                    continue;
                }
                grid.Hierarchy.QuerySphere(ref querySphere, _tmpNearByBlocks);
            }

            for (int l = 0; l < _tmpNearByBlocks.Count; l++)
            {
                var cube = _tmpNearByBlocks[l] as MyCubeBlock;
                if (cube == null || cube.EntityId == ignoredEntity || !WeaponCoreBlockDefs.ContainsKey(cube.BlockDefinition.Id.SubtypeId.String))
                {
                    continue;
                }

                if (!restriction.CheckForAnyWeapon && cube.BlockDefinition.Id.SubtypeId != subtype)
                {
                    continue;
                }

                if (checkBox)
                {
                    var cubeBox = new MyOrientedBoundingBoxD(cube.PositionComp.LocalAABB, cube.PositionComp.WorldMatrixRef);
                    if (restrictedBox.Contains(ref cubeBox) != ContainmentType.Disjoint)
                    {
                        return(true);
                    }
                }

                if (checkSphere && restrictedSphere.Contains(cube.PositionComp.WorldAABB) != ContainmentType.Disjoint)
                {
                    return(true);
                }
            }
            return(false);
        }