Example #1
0
        public override MyObjectBuilder_CubeBlock GetObjectBuilderCubeBlock(bool copy = false)
        {
            MyObjectBuilder_ProductionBlock objectBuilderCubeBlock = (MyObjectBuilder_ProductionBlock)base.GetObjectBuilderCubeBlock(copy);

            objectBuilderCubeBlock.InputInventory    = this.InputInventory.GetObjectBuilder();
            objectBuilderCubeBlock.OutputInventory   = this.OutputInventory.GetObjectBuilder();
            objectBuilderCubeBlock.UseConveyorSystem = (bool)this.m_useConveyorSystem;
            objectBuilderCubeBlock.NextItemId        = this.m_nextItemId;
            if (this.m_queue.Count <= 0)
            {
                objectBuilderCubeBlock.Queue = null;
            }
            else
            {
                objectBuilderCubeBlock.Queue = new MyObjectBuilder_ProductionBlock.QueueItem[this.m_queue.Count];
                for (int i = 0; i < this.m_queue.Count; i++)
                {
                    objectBuilderCubeBlock.Queue[i].Id     = (SerializableDefinitionId)this.m_queue[i].Blueprint.Id;
                    objectBuilderCubeBlock.Queue[i].Amount = this.m_queue[i].Amount;
                    objectBuilderCubeBlock.Queue[i].ItemId = new uint?(this.m_queue[i].ItemId);
                }
            }
            return(objectBuilderCubeBlock);
        }
Example #2
0
        private static bool CheckRevealBlockRules(IMyCubeGrid grid, List <IMyPlayer> players, out string reason)
        {
            reason = "";
            // This is actually faster, but doesn't include power checks

            // Live dangerously
            List <IMySlimBlock> blocks = new List <IMySlimBlock>();

            grid.GetBlocks(blocks, x => x.FatBlock != null);
            //CubeGrids.GetAllConnectedBlocks(_processedGrids, grid, blocks, x => x.FatBlock != null);
            //bool found = false;
            //bool powered = false;
            foreach (IMySlimBlock block in blocks)
            {
                IMyCubeBlock cubeBlock = block.FatBlock;

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Beacon))
                {
                    //MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyBeacon beacon = (IMyBeacon)cubeBlock;
                    if (!beacon.Enabled)
                    {
                        continue;
                    }

                    //Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
                    //if (!functionalBlock.Enabled)
                    //	continue;

                    //Console.WriteLine("Beacon: {0} {1} {2}", beacon.BroadcastRadius, terminalBlock.IsWorking, terminalBlock.IsFunctional);
                    //if (!terminalBlock.IsWorking)
                    //	continue;


                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < beacon.Radius)
                            {
                                //found = true;
                                //break;
                                reason = string.Format("{0} distance to beacon broadcast: {1}", player.DisplayName, distance);
                                return(true);
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_RadioAntenna))
                {
                    //MyObjectBuilder_RadioAntenna antenna = (MyObjectBuilder_RadioAntenna)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyRadioAntenna antenna = (IMyRadioAntenna)cubeBlock;

                    if (!antenna.Enabled)
                    {
                        continue;
                    }

                    //Sandbox.ModAPI.Ingame.IMyFunctionalBlock functionalBlock = (Sandbox.ModAPI.Ingame.IMyFunctionalBlock)cubeBlock;
                    //if (!functionalBlock.Enabled)
                    //	continue;

                    foreach (IMyPlayer player in players)
                    {
                        double distance = 0d;
                        if (Entity.GetDistanceBetweenPointAndPlayer(grid.GetPosition(), player, out distance))
                        {
                            if (distance < antenna.Radius)
                            {
                                //found = true;
                                //break;
                                reason = string.Format("{0} distance to antenna broadcast: {1}", player.DisplayName, distance);
                                return(true);
                            }
                        }
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_MedicalRoom))
                {
                    //MyObjectBuilder_MedicalRoom medical = (MyObjectBuilder_MedicalRoom)cubeBlock.GetObjectBuilderCubeBlock();
                    IMyMedicalRoom medical = (IMyMedicalRoom)cubeBlock;
                    if (!medical.Enabled)
                    {
                        continue;
                    }

                    IMyFunctionalBlock functionalBlock = (IMyFunctionalBlock)cubeBlock;
                    if (!functionalBlock.IsFunctional)
                    {
                        continue;
                    }

                    //if (!functionalBlock.Enabled)
                    //	continue;

                    if (PluginSettings.Instance.DynamicConcealIncludeMedBays)
                    {
                        lock (Online)
                        {
                            foreach (ulong connectedPlayer in Online)
                            {
                                long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
                                //if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
                                if (functionalBlock.OwnerId == playerId)
                                {
                                    reason = string.Format("Grid has medbay and player is logged in - playerid: {0}", playerId);
                                    return(true);
                                }

                                if (functionalBlock.GetUserRelationToOwner(playerId) == MyRelationsBetweenPlayerAndBlock.FactionShare)
                                {
                                    reason = string.Format("Grid has medbay and player is factionshare - playerid: {0}", playerId);
                                    return(true);
                                }
                            }
                        }

                        /*
                         * foreach (ulong connectedPlayer in PlayerManager.Instance.ConnectedPlayers)
                         * {
                         *      long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(connectedPlayer);
                         *      //if (medical.Owner == playerId || (medical.ShareMode == MyOwnershipShareModeEnum.Faction && Player.CheckPlayerSameFaction(medical.Owner, playerId)))
                         *      //if (functionalBlock.OwnerId == playerId || (functionalBlock.GetUserRelationToOwner(playerId) == Sandbox.Common.MyRelationsBetweenPlayerAndBlock.FactionShare))
                         *      if(medical.HasPlayerAccess(playerId))
                         *      {
                         *              reason = string.Format("Grid has medbay and player is logged in - playerid: {0}", playerId);
                         *              return true;
                         *      }
                         * }
                         */
                    }
                    else
                    {
                        reason = string.Format("Grid has medbay and conceal can not include medbays");
                        return(true);
                    }
                }

                if (cubeBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_ProductionBlock))
                {
                    MyObjectBuilder_ProductionBlock production = (MyObjectBuilder_ProductionBlock)cubeBlock.GetObjectBuilderCubeBlock();
                    if (!production.Enabled)
                    {
                        continue;
                    }

                    IMyProductionBlock productionBlock = (IMyProductionBlock)cubeBlock;
                    if (production.Queue.Length > 0)
                    {
                        reason = string.Format("Grid has production facility that has a queue");
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #3
0
 public ProductionBlockEntity(CubeGridEntity parent, MyObjectBuilder_ProductionBlock definition, Object backingObject)
     : base(parent, definition, backingObject)
 {
     m_inputInventory  = new InventoryEntity(definition.InputInventory, InternalGetInputInventory( ));
     m_outputInventory = new InventoryEntity(definition.OutputInventory, InternalGetOutputInventory( ));
 }
Example #4
0
 public ProductionBlockEntity(CubeGridEntity parent, MyObjectBuilder_ProductionBlock definition)
     : base(parent, definition)
 {
     m_inputInventory  = new InventoryEntity(definition.InputInventory);
     m_outputInventory = new InventoryEntity(definition.OutputInventory);
 }
Example #5
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.SyncFlag = true;
            MyResourceSinkComponent component = new MyResourceSinkComponent(1);

            component.Init(this.ProductionBlockDefinition.ResourceSinkGroup, this.ProductionBlockDefinition.OperationalPowerConsumption, new Func <float>(this.ComputeRequiredPower));
            component.IsPoweredChanged += new Action(this.Receiver_IsPoweredChanged);
            base.ResourceSink           = component;
            base.Init(objectBuilder, cubeGrid);
            MyObjectBuilder_ProductionBlock block = (MyObjectBuilder_ProductionBlock)objectBuilder;

            if (this.InventoryAggregate == null)
            {
                this.InventoryAggregate = new MyInventoryAggregate();
            }
            if (this.InputInventory == null)
            {
                this.InputInventory = new MyInventory(this.ProductionBlockDefinition.InventoryMaxVolume, this.ProductionBlockDefinition.InventorySize, MyInventoryFlags.CanReceive);
                if (block.InputInventory != null)
                {
                    this.InputInventory.Init(block.InputInventory);
                }
            }
            if (this.OutputInventory == null)
            {
                this.OutputInventory = new MyInventory(this.ProductionBlockDefinition.InventoryMaxVolume, this.ProductionBlockDefinition.InventorySize, MyInventoryFlags.CanSend);
                if (block.OutputInventory != null)
                {
                    this.OutputInventory.Init(block.OutputInventory);
                }
            }
            this.m_nextItemId = block.NextItemId;
            uint nextItemId = this.m_nextItemId;

            base.IsWorkingChanged += new Action <MyCubeBlock>(this.CubeBlock_IsWorkingChanged);
            base.ResourceSink.Update();
            base.SlimBlock.ComponentStack.IsFunctionalChanged += new Action(this.ComponentStack_IsFunctionalChanged);
            if (block.Queue != null)
            {
                this.m_queue.Clear();
                if (this.m_queue.Capacity < block.Queue.Length)
                {
                    this.m_queue.Capacity = block.Queue.Length;
                }
                int index = 0;
                while (true)
                {
                    if (index >= block.Queue.Length)
                    {
                        this.UpdatePower();
                        break;
                    }
                    MyObjectBuilder_ProductionBlock.QueueItem itemOb = block.Queue[index];
                    QueueItem item = this.DeserializeQueueItem(itemOb);
                    if (item.Blueprint != null)
                    {
                        this.m_queue.Add(item);
                    }
                    else
                    {
                        MySandboxGame.Log.WriteLine($"Could not add item into production block's queue: Blueprint {itemOb.Id} was not found.");
                    }
                    index++;
                }
            }
            this.m_useConveyorSystem.SetLocalValue(block.UseConveyorSystem);
            this.m_lastUpdateTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
        }