Esempio n. 1
0
        void Place(IMySlimBlock Block)
        {
            if (!Block.IsProjectable())
            {
                return;
            }
            var FirstItem = ((MyCubeBlockDefinition)Block.BlockDefinition).Components[0].Definition.Id;

            if (MyAPIGateway.Session.CreativeMode || ToolCargo.PullAny(OnboardInventoryOwners, FirstItem.SubtypeName, 1))
            {
                var Projector = ((Block.CubeGrid as MyCubeGrid).Projector as IMyProjector);
                Projector.Build(Block, 0, Tool.EntityId, false);
                ToolCargo.RemoveItemsOfType(1, FirstItem);
            }
            else
            {
                UnbuiltBlocks.Add(Block);
                SessionCore.DebugWrite($"{Tool.CustomName}.Place()", $"Tool can't pull the component {FirstItem.SubtypeName}!", IsExcessive: false);
            }
        }
Esempio n. 2
0
        void Weld(ICollection <IMySlimBlock> Blocks, int ticks = 1)
        {
            //UnbuiltBlocks.Clear();
            if (Blocks.Count == 0)
            {
                return;
            }
            float SpeedRatio               = (WelderSpeed / Blocks.Count) * ticks * SpeedMultiplier;
            float BoneFixSpeed             = WelderBoneRepairSpeed * ticks;
            var   UniqueBlocks             = Blocks.CollapseDuplicates();
            HashSet <IMySlimBlock> unbuilt = new HashSet <IMySlimBlock>();

            foreach (IMySlimBlock Block in UniqueBlocks.Keys)
            {
                float blockRatio = SpeedRatio * UniqueBlocks.GetData(Block);
                if (Block.CubeGrid.Physics?.Enabled == true)
                {
                    if (!Weld(Block, blockRatio, BoneFixSpeed))
                    {
                        unbuilt.Add(Block);
                    }
                }
                else
                {
                    Place(Block);
                }
            }

            if (unbuilt.Count > 0)
            {
                Dictionary <string, int> Missing = new Dictionary <string, int>();
                unbuilt.ReadMissingComponents(Missing);
                if (!ToolCargo.PullAny(OnboardInventoryOwners, Missing))
                {
                    UnbuiltBlocks.UnionWith(unbuilt);
                }
            }
        }
Esempio n. 3
0
        public override void UpdateBeforeSimulation100()
        {
            GridAvailablePower = ToolGrid.GetMaxPowerOutput();

            if (!Tool.Enabled)
            {
                return;
            }
            //if (RunTimesAvailable && MaxRunTime >= 0.25f)
            //    Text.AppendLine($"Performance impact: {(RunTimesAvailable ? Math.Round(AvgRunTime, 4).ToString() : "--")}/{(RunTimesAvailable ? Math.Round(MaxRunTime, 4).ToString() : "--")} ms (avg/max)");

            if (UnbuiltBlocks.Count > 0)
            {
                Dictionary <string, int> TotalMissingList = new Dictionary <string, int>();
                Dictionary <IMySlimBlock, Dictionary <string, int> > MissingPerBlock = new Dictionary <IMySlimBlock, Dictionary <string, int> >();
                UnbuiltBlocks.ReadMissingComponents(TotalMissingList, MissingPerBlock);
                if (!ToolCargo.PullAny(OnboardInventoryOwners, TotalMissingList))
                {
                    ComplainMissing(MissingPerBlock);
                }
                UnbuiltBlocks.Clear();
            }
        }
Esempio n. 4
0
 void Main(int ticks)
 {
     try
     {
         Tool.ResourceSink.SetRequiredInputByType(Electricity, PowerConsumptionFunc());
         if (Tool.IsToolWorking() && HasEnoughPower)
         {
             Work(ticks);
             DrawBeam();
         }
         else
         {
             DebugNote.Text = $"{Tool.CustomName}: idle";
             UnbuiltBlocks.Clear();
         }
         Tool.RefreshCustomInfo();
         //if (SessionCore.Debug) DebugNote.Text = $"{Tool.CustomName} perf. impact: {(RunTimesAvailable ? Math.Round(AvgRunTime, 5).ToString() : "--")}/{(RunTimesAvailable ? Math.Round(MaxRunTime, 5).ToString() : "--")} ms (avg/max)";
     }
     catch (Exception Scrap)
     {
         SessionCore.LogError(Tool.CustomName, Scrap);
     }
 }
Esempio n. 5
0
        void WeldDistanceMode(ICollection <IMySlimBlock> Blocks, int ticks = 1)
        {
            //UnbuiltBlocks.Clear();
            if (Blocks.Count == 0)
            {
                return;
            }
            Blocks = Blocks.OrderByDescending(x => Vector3D.DistanceSquared(x.GetPosition(), Tool.GetPosition())).ToList();
            float SpeedRatio   = WelderSpeed * ticks * SpeedMultiplier;
            float BoneFixSpeed = WelderBoneRepairSpeed * ticks;

            foreach (IMySlimBlock Block in Blocks)
            {
                if (Block.CubeGrid.Physics?.Enabled == true)
                {
                    bool welded = Weld(Block, SpeedRatio, BoneFixSpeed);
                    if (!welded)
                    {
                        var missing = Block.ReadMissingComponents();
                        if (!ToolCargo.PullAny(OnboardInventoryOwners, missing))
                        {
                            UnbuiltBlocks.Add(Block);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    Place(Block);
                    break;
                }
            }
        }