public virtual void OnAddedToGroup(MyGridLogicalGroupData group)
        {
            Debug.Assert(group.TerminalSystem != null, "Terminal system is null!");
            TerminalSystem      = group.TerminalSystem;
            ResourceDistributor = group.ResourceDistributor;
            WeaponSystem        = group.WeaponSystem;

            m_cubeGrid.OnBlockAdded   += ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved;
            m_cubeGrid.OnBlockRemoved += ResourceDistributor.CubeGrid_OnBlockAddedOrRemoved;

            ResourceDistributor.AddSink(GyroSystem.ResourceSink);
            ResourceDistributor.AddSink(ConveyorSystem.ResourceSink);
            ResourceDistributor.UpdateBeforeSimulation10();

            ConveyorSystem.ResourceSink.IsPoweredChanged += ResourceDistributor.ConveyorSystem_OnPoweredChanged;

            foreach (var g in m_cubeGrid.BlockGroups)
            {
                TerminalSystem.AddUpdateGroup(g);
            }
            TerminalSystem.GroupAdded   += m_terminalSystem_GroupAdded;
            TerminalSystem.GroupRemoved += m_terminalSystem_GroupRemoved;

            foreach (var block in m_cubeGrid.GetFatBlocks())
            {
                if (!block.MarkedForClose)
                {
                    var functionalBlock = block as MyTerminalBlock;
                    if (functionalBlock != null)
                    {
                        TerminalSystem.Add(functionalBlock);
                    }

                    var producer = block.Components.Get <MyResourceSourceComponent>();
                    if (producer != null)
                    {
                        ResourceDistributor.AddSource(producer);
                    }

                    var consumer = block.Components.Get <MyResourceSinkComponent>();
                    if (consumer != null)
                    {
                        ResourceDistributor.AddSink(consumer);
                    }

                    var socketOwner = block as IMyRechargeSocketOwner;
                    if (socketOwner != null)
                    {
                        socketOwner.RechargeSocket.ResourceDistributor = group.ResourceDistributor;
                    }

                    var weapon = block as IMyGunObject <MyDeviceBase>;
                    if (weapon != null)
                    {
                        WeaponSystem.Register(weapon);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void RegisterNewGrid(MyCubeGrid grid)
        {
            // Logic for picking proper grids goes here
            IMyShipController mainControl = null;

            foreach (IMyShipController controller in grid.GetFatBlocks <MyShipController>())
            {
                if (!controller.CustomData.Contains("DemoSetup"))
                {
                    continue;
                }
                mainControl = controller;
            }
            if (mainControl == null)
            {
                return;
            }
            WriteToLog("RegisterNewGrid", $"Registering new grid: {mainControl.CubeGrid.DisplayName}", LogType.General);
            ControllableGrid controllableGrid = new ControllableGrid(grid, mainControl);

            controllableGrid.OnWriteToLog += WriteToLog;
            controllableGrid.OnClose      += OnGridClose;
            controllableGrid.SetupGrid();
            _grids.Add(controllableGrid);
            _grids.ApplyAdditions();
        }
Ejemplo n.º 3
0
 public void ProcessProductionDowngradeList(MyCubeGrid attachedGridAsMyCubeGrid)
 {
     foreach (var block in attachedGridAsMyCubeGrid.GetFatBlocks())
     {
         if (block != null)
         {
             if (block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_OxygenGenerator))
             {
                 var blockAsOxyGen = block as IMyGasGenerator;
                 if (blockAsOxyGen != null)
                 {
                     blockAsOxyGen.ProductionCapacityMultiplier = 1.0f;
                     if (testColourOn)
                     {
                         blockAsOxyGen.CubeGrid.ColorBlocks(block.Position, block.Position, downgradeTestColor);
                     }
                 }
             }
             if (block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_Drill))
             {
                 var blockAsShipDrill = block as IMyShipDrill;
                 if (blockAsShipDrill != null)
                 {
                     blockAsShipDrill.DrillHarvestMultiplier = 1.0f;
                     if (testColourOn)
                     {
                         blockAsShipDrill.CubeGrid.ColorBlocks(block.Position, block.Position, downgradeTestColor);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
        async Task PunishGrid(MyCubeGrid grid)
        {
            var blocks = grid.GetFatBlocks();

            for (var i = 0; i < blocks.Count; i++)
            {
                // move to the next frame so we won't lag the server
                if (i % ProcessedBlockCountPerFrame == 0)
                {
                    await VRageUtils.MoveToGameLoop();
                }

                var block = blocks[i];
                if (block == null)
                {
                    continue;
                }

                switch (_config.PunishType)
                {
                case PunishType.Shutdown:
                {
                    DisableFunctionalBlock(block);
                    break;
                }

                case PunishType.Damage:
                {
                    DamageBlock(block);
                    break;
                }
                }
            }
        }
Ejemplo n.º 5
0
 public void ProcessEngineeringDowngradeList(MyCubeGrid attachedGridAsMyCubeGrid)
 {
     foreach (var block in attachedGridAsMyCubeGrid.GetFatBlocks())
     {
         if (block != null)
         {
             if (block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_Thrust))
             {
                 var blockAsThruster = block as IMyThrust;
                 if (blockAsThruster != null)
                 {
                     blockAsThruster.PowerConsumptionMultiplier = 1.0f;
                     if (testColourOn)
                     {
                         blockAsThruster.CubeGrid.ColorBlocks(block.Position, block.Position, downgradeTestColor);
                     }
                 }
             }
             if (block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_Gyro))
             {
                 var blockAsGryo = block as IMyGyro;
                 if (blockAsGryo != null)
                 {
                     blockAsGryo.PowerConsumptionMultiplier = 1.0f;
                     if (testColourOn)
                     {
                         blockAsGryo.CubeGrid.ColorBlocks(block.Position, block.Position, downgradeTestColor);
                     }
                 }
             }
             if (block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_Reactor))
             {
                 var blockAsReactor = block as IMyReactor;
                 if (blockAsReactor != null)
                 {
                     //MyAPIGateway.Utilities.ShowMessage("Downgrade Calc", blockAsReactor.PowerOutputMultiplier.ToString() + " " +
                     //                                                     powerOutputMulitplierControl.ToString() + " " +
                     //                                                     (blockAsReactor.PowerOutputMultiplier / powerOutputMulitplierControl).ToString());
                     blockAsReactor.PowerOutputMultiplier = 1.0f;
                     if (testColourOn)
                     {
                         blockAsReactor.CubeGrid.ColorBlocks(block.Position, block.Position, downgradeTestColor);
                     }
                 }
             }
             if (block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_Drill))
             {
                 var blockAsShipDrill = block as IMyShipDrill;
                 if (blockAsShipDrill != null)
                 {
                     blockAsShipDrill.PowerConsumptionMultiplier = 1.0f;
                     if (testColourOn)
                     {
                         blockAsShipDrill.CubeGrid.ColorBlocks(block.Position, block.Position, downgradeTestColor);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
        //private void SettingsRequest(ulong steamid)
        //{
        //	NetSettings.SetValue(Settings.Static);

        //	Tools.Debug(MyAPIGateway.Utilities.SerializeToXML(Settings.Static));

        //}

        private void Changed(VRage.Game.ModAPI.Interfaces.IMyControllableEntity o, VRage.Game.ModAPI.Interfaces.IMyControllableEntity n)
        {
            foreach (WeaponBase w in GridWeapons)
            {
                w.State.Value &= ~WeaponState.ManualShoot;
            }

            GridWeapons.Clear();
            ControlledGridId = 0;

            ActiveTurret = n?.Entity as IMyLargeTurretBase;

            if (ActiveTurret == null)
            {
                ActiveShipController = n?.Entity as IMyShipController;
                SelectedDefinitionId = Tools.GetSelectedHotbarDefinition(ActiveShipController);
            }

            MyCubeGrid grid = (n?.Entity as MyCubeBlock)?.CubeGrid;

            if (grid != null)
            {
                ControlledGridId = grid.EntityId;
                foreach (MyCubeBlock block in grid.GetFatBlocks())
                {
                    WeaponControlLayer layer = block.GameLogic.GetAs <WeaponControlLayer>();

                    if (layer != null)
                    {
                        GridWeapons.Add(layer.Weapon);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private static List <IMyInventory> GetInventories(IMyCubeBlock cube)
        {
            List <IMyCubeGrid> grids = new List <IMyCubeGrid>();

            MyAPIGateway.GridGroups.GetGroup(cube.CubeGrid, GridLinkTypeEnum.Logical, grids);
            List <IMyInventory> inventories = new List <IMyInventory>();
            long owner = cube.OwnerId;

            foreach (IMyCubeGrid g in grids)
            {
                MyCubeGrid grid = (MyCubeGrid)g;
                foreach (var block in grid.GetFatBlocks())
                {
                    if (owner != 0)
                    {
                        MyRelationsBetweenPlayerAndBlock relation = block.GetUserRelationToOwner(owner);
                        if (relation == MyRelationsBetweenPlayerAndBlock.Enemies)
                        {
                            continue;
                        }
                    }

                    for (int i = 0; i < block.InventoryCount; i++)
                    {
                        IMyInventory inv = ((IMyCubeBlock)block).GetInventory(i);
                        inventories.Add(inv);
                    }
                }
            }
            return(inventories);
        }
Ejemplo n.º 8
0
        private bool Add(MyCubeGrid grid)
        {
            if (grid == null)
            {
                throw new NullReferenceException("Attempt to add a null grid.");
            }

            if (!grids.Add(grid))
            {
                throw new ArgumentException("Grid already exists.");
            }

            if (grid.IsStatic)
            {
                staticCount++;
            }
            grid.OnBlockAdded    += Grid_OnBlockAdded;
            grid.OnBlockRemoved  += Grid_OnBlockRemoved;
            grid.OnStaticChanged += Grid_OnIsStaticChanged;
            grid.OnClose         += Grid_OnClose;
            grid.OnGridSplit     += Grid_OnGridSplit;

            foreach (MyCubeBlock s in grid.GetFatBlocks())
            {
                Grid_OnBlockAdded(s.SlimBlock);
            }

            return(true);
        }
        public static Boolean DoesGridHaveCaptureBlock(MyCubeGrid grid, KothConfig koth)
        {
            foreach (MyCubeBlock block in grid.GetFatBlocks())
            {
                if (block != null && block.BlockDefinition != null)
                {
                    Log.Info(block.BlockDefinition.Id.TypeId + " " + block.BlockDefinition.Id.SubtypeName);
                }
                else
                {
                    Log.Info("Null id for capture block");
                }

                if (block.OwnerId > 0 && block.BlockDefinition.Id.TypeId.ToString().Replace("MyObjectBuilder_", "").Equals(koth.captureBlockType) && block.BlockDefinition.Id.SubtypeName.Equals(koth.captureBlockSubtype))
                {
                    if (block.IsFunctional && block.IsWorking)
                    {
                        if (block is Sandbox.ModAPI.IMyFunctionalBlock bl)
                        {
                            bl.Enabled = true;
                        }

                        if (block is Sandbox.ModAPI.IMyBeacon beacon)
                        {
                            beacon.Radius = koth.captureBlockBroadcastDistance;
                        }

                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 10
0
        internal void RemoveCoreToolbarWeapons(MyCubeGrid grid)
        {
            foreach (var cube in grid.GetFatBlocks())
            {
                if (cube is MyShipController)
                {
                    var ob     = (MyObjectBuilder_ShipController)cube.GetObjectBuilderCubeBlock();
                    var reinit = false;
                    for (int i = 0; i < ob.Toolbar.Slots.Count; i++)
                    {
                        var toolbarItem = ob.Toolbar.Slots[i].Data as MyObjectBuilder_ToolbarItemWeapon;
                        if (toolbarItem != null)
                        {
                            var defId = (MyDefinitionId)toolbarItem.defId;
                            if ((ReplaceVanilla && VanillaIds.ContainsKey(defId)) || WeaponPlatforms.ContainsKey(defId.SubtypeId))
                            {
                                var index = ob.Toolbar.Slots[i].Index;
                                var item  = ob.Toolbar.Slots[i].Item;
                                ob.Toolbar.Slots[i] = new MyObjectBuilder_Toolbar.Slot {
                                    Index = index, Item = item
                                };
                                reinit = true;
                            }
                        }
                    }

                    if (reinit)
                    {
                        cube.Init(ob, grid);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public void UnRegisterSubGrid(MyCubeGrid grid, bool clean = false)
        {
            if (!SubGridsRegistered.Contains(grid))
            {
                Log.Line($"sub Grid Already UnRegistered: [Main]:{grid == MyGrid}");
            }

            if (!clean)
            {
                SubGrids.Remove(grid);
            }

            SubGridsRegistered.Remove(grid);
            grid.OnFatBlockAdded   -= FatBlockAdded;
            grid.OnFatBlockRemoved -= FatBlockRemoved;

            foreach (var cube in grid.GetFatBlocks())
            {
                var battery = cube as MyBatteryBlock;
                if (InventoryMonitor.ContainsKey(cube) || battery != null && Batteries.Contains(battery))
                {
                    FatBlockRemoved(cube);
                }
            }

            GridAi removeAi;

            if (!Session.GridTargetingAIs.ContainsKey(grid))
            {
                Session.GridToMasterAi.TryRemove(grid, out removeAi);
            }
        }
Ejemplo n.º 12
0
        // NOTE: object is re-used, this is called when retrieved from pool.
        public void Init(MyCubeGrid grid)
        {
            try
            {
                if (grid == null)
                {
                    throw new Exception("given grid was null!");
                }

                Grid = grid;
                RealisticThrusters = true;
                _lastCheckedOwner  = -1;
                ForcedRealistic    = false;

                // NOTE: not all blocks are fatblocks, but the kind of blocks we need are always fatblocks.
                foreach (var block in Grid.GetFatBlocks())
                {
                    BlockAdded(block);
                }

                Grid.OnFatBlockAdded   += BlockAdded;
                Grid.OnFatBlockRemoved += BlockRemoved;

                Update();
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Ejemplo n.º 13
0
 public void ProcessCombatMobilityDowngradeList(MyCubeGrid attachedGridAsMyCubeGrid)
 {
     foreach (var block in attachedGridAsMyCubeGrid.GetFatBlocks())
     {
         if (block != null)
         {
             if (block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_Thrust))
             {
                 var blockAsThruster = block as Sandbox.ModAPI.IMyThrust;
                 if (blockAsThruster != null)
                 {
                     blockAsThruster.ThrustMultiplier = 1.0f;
                 }
                 if (testColourOn)
                 {
                     blockAsThruster.CubeGrid.ColorBlocks(block.Position, block.Position, downgradeTestColor);
                 }
             }
             if (block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_Gyro))
             {
                 var blockAsGryo = block as Sandbox.ModAPI.IMyGyro;
                 if (blockAsGryo != null)
                 {
                     blockAsGryo.GyroStrengthMultiplier     = 1.0f;
                     blockAsGryo.PowerConsumptionMultiplier = 1.0f;
                 }
                 if (testColourOn)
                 {
                     blockAsGryo.CubeGrid.ColorBlocks(block.Position, block.Position, downgradeTestColor);
                 }
             }
         }
     }
 }
Ejemplo n.º 14
0
 private static void RemoveCharacters(MyCubeGrid Grid)
 {
     foreach (var blck in Grid.GetFatBlocks().OfType <MyCockpit>())
     {
         if (blck.Pilot != null)
         {
             blck.RequestRemovePilot();
             blck.RemovePilot();
         }
     }
 }
Ejemplo n.º 15
0
        private void DisableProjectors(MyCubeGrid grid)
        {
            foreach (var projector in grid.GetFatBlocks <MyProjectorBase>())
            {
                if (projector.ProjectedGrid == null)
                {
                    continue;
                }

                projector.Enabled = false;
                _projectors.Add(projector.EntityId);
            }
        }
Ejemplo n.º 16
0
        private static void TurnShipReactorsOnOff(MyEntity entity, bool newState)
        {
            MyCubeGrid grid = entity as MyCubeGrid;

            Debug.Assert(grid != null, "Ship prefab was not a ship");
            if (grid != null)
            {
                foreach (var reactor in grid.GetFatBlocks <MyReactor>())
                {
                    reactor.Enabled = newState;
                }
            }
        }
Ejemplo n.º 17
0
        public static List <VRage.Game.ModAPI.IMyInventory> GetInventories(MyCubeGrid grid)
        {
            List <VRage.Game.ModAPI.IMyInventory> inventories = new List <VRage.Game.ModAPI.IMyInventory>();

            foreach (var block in grid.GetFatBlocks())
            {
                for (int i = 0; i < block.InventoryCount; i++)
                {
                    VRage.Game.ModAPI.IMyInventory inv = ((VRage.Game.ModAPI.IMyCubeBlock)block).GetInventory(i);
                    inventories.Add(inv);
                }
            }
            return(inventories);
        }
Ejemplo n.º 18
0
        public GridViewModel(MyCubeGrid grid, EntityTreeViewModel tree) : base(grid, tree)
        {
            TorchBase.Instance.InvokeBlocking(() =>
            {
                foreach (var block in grid.GetFatBlocks().Where(b => b is IMyTerminalBlock))
                {
                    Blocks.Add(new BlockViewModel((IMyTerminalBlock)block, tree));
                }
            });
            Blocks.Sort(b => b.Block.GetType().AssemblyQualifiedName);

            grid.OnBlockAdded   += Grid_OnBlockAdded;
            grid.OnBlockRemoved += Grid_OnBlockRemoved;
        }
Ejemplo n.º 19
0
        public void SetupGrid()
        {
            foreach (MyCubeBlock block in _thisGrid.GetFatBlocks())
            {
                MyThrust myThrust = block as MyThrust;
                if (myThrust != null)
                {
                    _gridSystems.ControllableThrusters.AddNewThruster(myThrust);
                    WriteToLog("SetupGrid", $"Adding Thruster {myThrust.GridThrustDirection}", LogType.General);
                    continue;
                }

                MyGyro myGyro = block as MyGyro;
                if (myGyro != null)
                {
                    _gridSystems.ControllableGyros.Add(myGyro);
                    WriteToLog("SetupGrid", $"Adding Gyro", LogType.General);
                    continue;
                }

                IMyTextSurface surface = block as IMyTextSurface;
                if (surface != null)
                {
                    if (((IMyTerminalBlock)surface).CustomData.Contains("DebugL"))
                    {
                        _gridSystems.DebugScreens.AddLeftScreen(surface);
                        _gridSystems.DebugScreens.WriteToLeft(new StringBuilder("Left Debug Screen Detected"));
                        WriteToLog("SetupGrid", $"Adding Left Debug Screen", LogType.General);
                    }

                    if (((IMyTerminalBlock)surface).CustomData.Contains("DebugR"))
                    {
                        _gridSystems.DebugScreens.AddRightScreen(surface);
                        _gridSystems.DebugScreens.WriteToRight(new StringBuilder("Right Debug Screen Detected"));
                        WriteToLog("SetupGrid", $"Adding Right Debug Screen", LogType.General);
                    }
                    continue;
                }

                IMyLandingGear gear = block as IMyLandingGear;
                if (gear == null)
                {
                    continue;
                }
                _gridSystems.ControllableLandingGear.Add(gear);
            }
        }
Ejemplo n.º 20
0
        public static BroadcastError ValidateBlockRequirements(BroadcastInfo broadcastInfo)
        {
            if (_ModConfig.MinBlockCount > 0 && broadcastInfo.BlockCount < _ModConfig.MinBlockCount)
            {
                return(BroadcastError.NotEnoughBlocks);
            }

            MyCubeGrid cubeGrid = MyVisualScriptLogicProvider.GetEntityById(broadcastInfo.EntityId) as MyCubeGrid;

            if (cubeGrid != null && cubeGrid.GetFatBlocks().Count < _ModConfig.MinFatBlockCount)
            {
                // Probably not an interesting grid
                return(BroadcastError.NotEnoughFatBlocks);
            }

            return(BroadcastError.Ok);
        }
Ejemplo n.º 21
0
        public void Init(MyCubeGrid grid)
        {
            if (Grid != null)
            {
                return;
            }

            Grid = grid;

            foreach (MyCubeBlock block in grid.GetFatBlocks())
            {
                AddBlockInventory(block);
            }

            ((IMyCubeGrid)Grid).OnBlockAdded   += AddBlockInventory;
            ((IMyCubeGrid)Grid).OnBlockRemoved += RemoveBlockInventory;
        }
Ejemplo n.º 22
0
        public void Init(MyCubeGrid grid)
        {
            PlayerOwnedBlocks      = new Dictionary <long, int>();
            PlayerOwnedValidBlocks = new Dictionary <long, int>();

            BigOwners   = new List <long>();
            SmallOwners = new List <long>();

            MaxBlocks    = 0;
            gridEntityId = grid.EntityId;

            //Finds max blocks within owners: Slow!
            foreach (var block in grid.GetFatBlocks <MyCubeBlock>())
            {
                var blockOwner = block.OwnerId;

                if (blockOwner == 0)
                {
                    continue;
                }

                if (!PlayerOwnedBlocks.ContainsKey(blockOwner))
                {
                    PlayerOwnedBlocks.Add(blockOwner, 0);
                }

                PlayerOwnedBlocks[blockOwner]++;

                if (!IsValidBlock(block))
                {
                    continue;
                }

                if (!PlayerOwnedValidBlocks.ContainsKey(blockOwner))
                {
                    PlayerOwnedValidBlocks.Add(blockOwner, 0);
                }

                if (++PlayerOwnedValidBlocks[block.OwnerId] > MaxBlocks)
                {
                    MaxBlocks = PlayerOwnedValidBlocks[blockOwner];
                }
            }

            NeedRecalculateOwners = true;
        }
Ejemplo n.º 23
0
        public static long GetBiggestOwner(this MyCubeGrid grid)
        {
            var FatBlocks = grid.GetFatBlocks().ToList();

            int TotalFatBlocks = 0;


            Dictionary <long, int> owners = new Dictionary <long, int>();

            foreach (var fat in FatBlocks)
            {
                //Only count blocks with ownership
                if (!fat.IsFunctional || fat.IDModule == null)
                {
                    continue;
                }


                //WTF happened here?
                //if (fat.OwnerId == 0)
                //   Log.Error($"WTF: {fat.BlockDefinition.Id} - {fat.GetType()} - {fat.OwnerId}");


                TotalFatBlocks++;


                if (fat.OwnerId != 0)
                {
                    if (!owners.ContainsKey(fat.OwnerId))
                    {
                        owners.Add(fat.OwnerId, 1);
                    }
                    else
                    {
                        owners[fat.OwnerId] += 1;
                    }
                }
            }

            if (owners.Count == 0)
            {
                return(0);
            }

            return(owners.FirstOrDefault(x => x.Value == owners.Values.Max()).Key);
        }
 private void TryGetShipController()
 {
     try
     {
         foreach (var block2 in CubeGrid.GetFatBlocks())
         {
             if (block2 != null && block2 is MyShipController)
             {
                 var newController = block2 as MyShipController;
                 m_shipController = newController;
                 break;
             }
         }
     }
     catch (Exception e)
     { Debug.HandleException(e); }
 }
Ejemplo n.º 25
0
        public static int CalculateGridThreat(MyCubeGrid grid)
        {
            float threat = 0;

            foreach (MyCubeBlock block in grid.GetFatBlocks())
            {
                if (!block.IsFunctional)
                {
                    continue;
                }
                if (block is IMyLargeMissileTurret)
                {
                    threat += 750;
                    continue;
                }
                if (block is IMyLargeGatlingTurret)
                {
                    threat += 750;
                    continue;
                }
                if (block is IMySmallMissileLauncher)
                {
                    threat += 300;
                    continue;
                }
                if (block is IMySmallGatlingGun)
                {
                    threat += 300;
                    continue;
                }
                if (block is IMyLargeInteriorTurret)
                {
                    threat += 200;
                    continue;
                }
            }

            if (grid.IsStatic || grid.IsUnsupportedStation)
            {
                threat /= 2;
            }

            return(grid.GridSizeEnum == MyCubeSize.Large ? (int)threat * 3 : (int)threat);
        }
Ejemplo n.º 26
0
 public void ProcessProductionUpgradeList(MyCubeGrid attachedGridAsMyCubeGrid)
 {
     try
     {
         foreach (var block in attachedGridAsMyCubeGrid.GetFatBlocks())
         {
             if (block != null)
             {
                 if (block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_OxygenGenerator))
                 {
                     var blockAsOxyGen = block as IMyGasGenerator;
                     if (blockAsOxyGen != null)
                     {
                         blockAsOxyGen.ProductionCapacityMultiplier = 1.0f;
                         blockAsOxyGen.ProductionCapacityMultiplier = (blockAsOxyGen.ProductionCapacityMultiplier / gasGeneratorOutputMulitplierControl);
                         if (testColourOn)
                         {
                             blockAsOxyGen.CubeGrid.ColorBlocks(block.Position, block.Position, upgradeTestColor);
                         }
                     }
                 }
                 if (block.BlockDefinition.Id.TypeId == typeof(MyObjectBuilder_Drill))
                 {
                     var blockAsShipDrill = block as IMyShipDrill;
                     if (blockAsShipDrill != null)
                     {
                         blockAsShipDrill.DrillHarvestMultiplier = 1.0f;
                         blockAsShipDrill.DrillHarvestMultiplier = (blockAsShipDrill.DrillHarvestMultiplier * drillOutputMulitplierControl);
                         if (testColourOn)
                         {
                             blockAsShipDrill.CubeGrid.ColorBlocks(block.Position, block.Position, upgradeTestColor);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         //MyVisualScriptLogicProvider.ShowNotificationToAll("Upgrade Error " + e, 10000, "Red");
     }
 }
Ejemplo n.º 27
0
        public void RegisterSubGrid(MyCubeGrid grid, bool dupCheck = false)
        {
            if (dupCheck && SubGridsRegistered.Contains(grid))
            {
                Log.Line($"sub Grid Already Registered: [Main]:{grid == MyGrid}");
            }

            grid.Flags             |= (EntityFlags)(1 << 31);
            grid.OnFatBlockAdded   += FatBlockAdded;
            grid.OnFatBlockRemoved += FatBlockRemoved;

            SubGridsRegistered.Add(grid);

            foreach (var cube in grid.GetFatBlocks())
            {
                var battery = cube as MyBatteryBlock;
                if (battery != null || cube.HasInventory)
                {
                    FatBlockAdded(cube);
                }
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Hacky way to get the ResourceDistributorComponent from a grid
        /// without benefit of the GridSystems.
        /// <para>Unfriendly to performance. Use sparingly and cache result.</para>
        /// </summary>
        /// <param name="grid"></param>
        /// <returns></returns>
        public static MyResourceDistributorComponent GetDistributor(MyCubeGrid grid)
        {
            if (grid == null || !grid.CubeBlocks.Any())
            {
                return(null);
            }

            //attempt to grab the distributor from an extant ship controller
            var controller = grid.GetFatBlocks().FirstOrDefault(b => (b as MyShipController)?.GridResourceDistributor != null);

            if (controller != null)
            {
                return(((MyShipController)controller).GridResourceDistributor);
            }
            //didn't find a controller, so let's make one

            var ob = MyAPIGateway.Utilities.SerializeFromXML <MyObjectBuilder_Cockpit>(OB);

            //assign a random entity ID and hope we don't get collisions
            ob.EntityId = _random.Next(int.MinValue, int.MaxValue);
            //block position to something that will probably not have a block there already
            ob.Min = grid.WorldToGridInteger(grid.PositionComp.WorldAABB.Min) - new Vector3I(2);
            //note that this will slightly inflate the grid's boundingbox, but the Raze call later triggers a bounds recalc in 30 seconds

            //not exposed in the class but is in the interface???
            //also not synced
            var blk         = ((IMyCubeGrid)grid).AddBlock(ob, false);
            var distributor = (blk.FatBlock as MyShipController)?.GridResourceDistributor;

            //hack to make it work on clients (removal not synced)
            grid.RazeBlocksClient(new List <Vector3I>()
            {
                blk.Position
            });
            //we don't need the block itself, we grabbed the distributor earlier
            blk.FatBlock?.Close();

            return(distributor);
        }
Ejemplo n.º 29
0
 public void Init(MyCubeGrid grid)
 {
     this.PlayerOwnedBlocks      = new Dictionary <long, int>();
     this.PlayerOwnedValidBlocks = new Dictionary <long, int>();
     this.BigOwners    = new List <long>();
     this.SmallOwners  = new List <long>();
     this.MaxBlocks    = 0;
     this.gridEntityId = grid.EntityId;
     foreach (MyCubeBlock block in grid.GetFatBlocks())
     {
         long ownerId = block.OwnerId;
         if (ownerId != 0)
         {
             if (!this.PlayerOwnedBlocks.ContainsKey(ownerId))
             {
                 this.PlayerOwnedBlocks.Add(ownerId, 0);
             }
             long num2 = ownerId;
             this.PlayerOwnedBlocks[num2] += 1;
             if (this.IsValidBlock(block))
             {
                 if (!this.PlayerOwnedValidBlocks.ContainsKey(ownerId))
                 {
                     this.PlayerOwnedValidBlocks.Add(ownerId, 0);
                 }
                 num2 = block.OwnerId;
                 int num3 = this.PlayerOwnedValidBlocks[num2] + 1;
                 this.PlayerOwnedValidBlocks[num2] = num3;
                 if (num3 > this.MaxBlocks)
                 {
                     this.MaxBlocks = this.PlayerOwnedValidBlocks[ownerId];
                 }
             }
         }
     }
     this.NeedRecalculateOwners = true;
 }
        public void Init(MyCubeGrid grid)
        {
            PlayerOwnedBlocks = new Dictionary<long, int>();
            PlayerOwnedValidBlocks = new Dictionary<long, int>();

            BigOwners = new List<long>();
            SmallOwners = new List<long>();

            MaxBlocks = 0;
            gridEntityId = grid.EntityId;

            //Finds max blocks within owners: Slow!
            foreach (var block in grid.GetFatBlocks<MyCubeBlock>())
            {
                var blockOwner = block.OwnerId;

                if (blockOwner == 0)
                    continue;

                if (!PlayerOwnedBlocks.ContainsKey(blockOwner))
                    PlayerOwnedBlocks.Add(blockOwner, 0);

                PlayerOwnedBlocks[blockOwner]++;

                if (!IsValidBlock(block))
                    continue;

                if (!PlayerOwnedValidBlocks.ContainsKey(blockOwner))
                    PlayerOwnedValidBlocks.Add(blockOwner, 0);

                if (++PlayerOwnedValidBlocks[block.OwnerId] > MaxBlocks)
                    MaxBlocks = PlayerOwnedValidBlocks[blockOwner];

            }

            NeedRecalculateOwners = true;
        }
        private long CountProjectionPCU(MyCubeGrid grid)
        {
            long pcu = 0;

            /* loop over the projectors in the grid */
            foreach (var projector in grid.GetFatBlocks().OfType <MyProjectorBase>())
            {
                /* if the projector isn't enabled, dont count its projected pcu */
                if (!projector.Enabled)
                {
                    continue;
                }

                List <MyCubeGrid> grids = projector.Clipboard.PreviewGrids;

                /* count the blocks in the projected grid */
                foreach (MyCubeGrid CubeGrid in grids)
                {
                    pcu += CubeGrid.CubeBlocks.Count;
                }
            }

            return(pcu);
        }