public override void UpdateOnceBeforeFrame()
        {
            try {
                base.UpdateOnceBeforeFrame();

                m_block = new NaniteConstructionBlock(Entity);

                if (!NaniteConstructionManager.NaniteBlocks.ContainsKey(Entity.EntityId))
                {
                    NaniteConstructionManager.NaniteBlocks.Add(Entity.EntityId, m_block);
                }

                m_block.UpdateCount += NaniteConstructionManager.NaniteBlocks.Count * 30;
                // Adds some gap between factory processing so they don't all process their targets at once.

                IMySlimBlock slimBlock = ((MyCubeBlock)m_block.ConstructionBlock).SlimBlock as IMySlimBlock;
                Logging.Instance.WriteLine(string.Format("ADDING Nanite Factory: conid={0} physics={1} ratio={2}",
                                                         Entity.EntityId, m_block.ConstructionBlock.CubeGrid.Physics == null, slimBlock.BuildLevelRatio), 1);

                if (NaniteConstructionManager.NaniteSync != null)
                {
                    NaniteConstructionManager.NaniteSync.SendNeedTerminalSettings(Entity.EntityId);
                }
            } catch (Exception exc) {
                MyLog.Default.WriteLineAndConsole($"##MOD: Nanites UpdateOnceBeforeFrame, ERROR: {exc}");
            }
        }
 public NaniteMiningTargets(NaniteConstructionBlock constructionBlock) : base(constructionBlock)
 {
     m_maxDistance        = NaniteConstructionManager.Settings.MiningMaxDistance;
     m_targetTracker      = new Dictionary <NaniteMiningItem, NaniteMiningTarget>();
     m_globalPositionList = new HashSet <Vector3D>();
     rnd = new Random();
 }
Beispiel #3
0
 public NaniteTargetBlocksBase(NaniteConstructionBlock constructionBlock)
 {
     m_lock                = new FastResourceLock();
     m_targetList          = new List <object>();
     m_potentialTargetList = new List <object>();
     m_componentsRequired  = new Dictionary <string, int>();
     m_constructionBlock   = constructionBlock;
 }
        public NaniteMedicalTargets(NaniteConstructionBlock constructionBlock) : base(constructionBlock)
        {
            m_maxDistance   = NaniteConstructionManager.Settings.MedicalMaxDistance;
            m_targetTracker = new Dictionary <IMyPlayer, NaniteMedicalTarget>();

            m_progressSoundEmitter = new MyEntity3DSoundEmitter((MyEntity)constructionBlock.ConstructionBlock);
            m_progressSound        = new MySoundPair("BlockMedicalProgress");
        }
 public NaniteConstructionTargets(NaniteConstructionBlock constructionBlock) : base(constructionBlock)
 {
     m_targetBlocks     = new Dictionary <IMySlimBlock, int>();
     m_maxDistance      = NaniteConstructionManager.Settings.ConstructionMaxBeaconDistance;
     m_remoteTargets    = new HashSet <IMySlimBlock>();
     m_remoteLock       = new FastResourceLock();
     m_areaTargetBlocks = new Dictionary <IMySlimBlock, NaniteAreaBeacon>();
 }
        public NaniteDeconstructionTargets(NaniteConstructionBlock block) : base(block)
        {
            m_validBeaconedGrids = new HashSet <NaniteDeconstructionGrid>();
            m_targetBlocks       = new Dictionary <IMySlimBlock, int>();
            m_tempPhysicless     = new Dictionary <IMyCubeGrid, DateTime>();
            m_areaTargetBlocks   = new Dictionary <IMyCubeGrid, NaniteAreaBeacon>();
            m_maxDistance        = NaniteConstructionManager.Settings.DeconstructionMaxDistance;

            MyAPIGateway.Entities.OnEntityRemove += OnEntityRemove;
        }
        internal static bool HasRequiredPowerForCurrentTarget(IMyFunctionalBlock constructionBlock)
        {
            if (!NaniteConstructionManager.NaniteBlocks.ContainsKey(constructionBlock.EntityId))
            {
                return(false);
            }

            NaniteConstructionBlock block = NaniteConstructionManager.NaniteBlocks[constructionBlock.EntityId];
            var powerRequired             = block.Targets.Sum(x => x.TargetList.Count * x.GetPowerUsage());

            return(HasRequiredPower(constructionBlock, powerRequired));
        }
Beispiel #8
0
        internal bool IsInRange(NaniteConstructionBlock factory, IMySlimBlock block, float range)
        {
            range = System.Math.Min(range, MyAPIGateway.Session.SessionSettings.SyncDistance);

            if (factory.ConstructionBlock != null && IsEnabled(factory) &&
                Vector3D.DistanceSquared(factory.ConstructionBlock.GetPosition(), EntityHelper.GetBlockPosition(block)) < range * range)
            {
                return(true);
            }

            return(false);
        }
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            m_block = new NaniteConstructionBlock(Entity);
            NaniteConstructionManager.NaniteBlocks.Add(Entity.EntityId, m_block);
            IMySlimBlock slimBlock = ((MyCubeBlock)m_block.ConstructionBlock).SlimBlock as IMySlimBlock;

            Logging.Instance.WriteLine(string.Format("ADDING Nanite Factory: conid={0} physics={1} ratio={2}", Entity.EntityId, m_block.ConstructionBlock.CubeGrid.Physics == null, slimBlock.BuildLevelRatio));

            if (NaniteConstructionManager.NaniteSync != null)
            {
                NaniteConstructionManager.NaniteSync.SendNeedTerminalSettings(Entity.EntityId);
            }
        }
        public override bool IsEnabled(NaniteConstructionBlock factory)
        {
            if (!((IMyFunctionalBlock)factory.ConstructionBlock).Enabled ||
                !((IMyFunctionalBlock)factory.ConstructionBlock).IsFunctional ||
                (NaniteConstructionManager.TerminalSettings.ContainsKey(factory.ConstructionBlock.EntityId) &&
                 !NaniteConstructionManager.TerminalSettings[factory.ConstructionBlock.EntityId].AllowRepair))
            {
                factory.EnabledParticleTargets[TargetName] = false;
                return(false);
            }

            factory.EnabledParticleTargets[TargetName] = true;
            return(true);
        }
Beispiel #11
0
        private void CreateProjectionParticle(IMySlimBlock target)
        {
            if (!m_targetBlocks.ContainsKey(target))
            {
                Logging.Instance.WriteLine($"[Projection] Adding ProjectionParticle Target: {target.Position}", 1);
                NaniteProjectionTarget projectionTarget = new NaniteProjectionTarget();
                projectionTarget.ParticleCount = 0;
                projectionTarget.StartTime     = (int)MyAPIGateway.Session.ElapsedPlayTime.TotalMilliseconds;
                m_targetBlocks.Add(target, projectionTarget);
            }

            MyAPIGateway.Parallel.Start(() =>
            {
                try
                {
                    Vector3D targetPosition = default(Vector3D);

                    if (target.FatBlock != null)
                    {
                        targetPosition = target.FatBlock.GetPosition();
                    }
                    else
                    {
                        var size = target.CubeGrid.GridSizeEnum == MyCubeSize.Small ? 0.5f : 2.5f;
                        var destinationPosition = new Vector3D(target.Position * size);
                        targetPosition          = Vector3D.Transform(destinationPosition, target.CubeGrid.WorldMatrix);
                    }

                    NaniteConstructionBlock nearestFactory = GetNearestFactory(TargetName, targetPosition);

                    Vector4 startColor = new Vector4(0.95f, 0.0f, 0.95f, 0.75f);
                    Vector4 endColor   = new Vector4(0.035f, 0.0f, 0.35f, 0.75f);

                    if (nearestFactory.ParticleManager.Particles.Count < NaniteParticleManager.MaxTotalParticles)
                    {
                        MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                        {
                            nearestFactory.ParticleManager.AddParticle(startColor, endColor, GetMinTravelTime() * 1000f, GetSpeed(), target);
                        });
                    }
                }
                catch (Exception e)
                { Logging.Instance.WriteLine($"{e}"); }
            });
        }
Beispiel #12
0
        public NaniteToolBase(NaniteConstructionBlock constructionBlock, IMySlimBlock block, int waitTime, string toolBuilderText, bool performanceFriendly, bool isGrinder)
        {
            if (block == null)
            {
                Logging.Instance.WriteLine("Block is null!");
                return;
            }

            m_targetBlock         = block;
            m_startTime           = (int)MyAPIGateway.Session.ElapsedPlayTime.TotalMilliseconds;
            m_waitTime            = waitTime;
            m_constructionBlock   = constructionBlock;
            m_performanceFriendly = performanceFriendly;
            m_isGrinder           = isGrinder;
            m_updateCount         = 0;

            m_missingComponents = new Dictionary <string, int>();
            m_inventory         = new Dictionary <string, MyTuple <MyFixedPoint, MyObjectBuilder_PhysicalObject> >();

            CreateTool();
        }
Beispiel #13
0
        public NaniteToolBaseOld(NaniteConstructionBlock constructionBlock, IMySlimBlock block, int waitTime, string toolBuilderText, bool performanceFriendly, bool isGrinder)
        {
            if (block == null)
            {
                Logging.Instance.WriteLine("Block is null!");
                return;
            }

            m_targetBlock = block;
            Vector3D position = Vector3D.Zero;

            if (block.FatBlock == null)
            {
                position = Vector3D.Transform(block.Position * (block.CubeGrid.GridSizeEnum == MyCubeSize.Small ? 0.5f : 2.5f), block.CubeGrid.WorldMatrix);
            }
            else
            {
                position = block.FatBlock.GetPosition();
            }

            m_startTime           = (int)MyAPIGateway.Session.ElapsedPlayTime.TotalMilliseconds;
            m_waitTime            = waitTime;
            m_constructionBlock   = constructionBlock;
            m_performanceFriendly = performanceFriendly;
            m_isGrinder           = isGrinder;
            m_missingComponents   = new Dictionary <string, int>();
            m_inventory           = new Dictionary <string, MyTuple <MyFixedPoint, MyObjectBuilder_PhysicalObject> >();
            m_removed             = false;

            if (!performanceFriendly)
            {
                CreateTool(block.CubeGrid.GridSizeEnum, toolBuilderText);
            }
            else
            {
                CreatePerformanceTool();
            }

            //Logging.Instance.WriteLine("Init");
        }
Beispiel #14
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            if (m_lock == null)
            {
                m_lock = new FastResourceLock();
            }

            base.Init(objectBuilder);
            using (m_lock.AcquireExclusiveUsing())
            {
                if (!NaniteConstructionManager.NaniteBlocks.ContainsKey(Entity.EntityId))
                {
                    m_block = new NaniteConstructionBlock(Entity);
                    NaniteConstructionManager.NaniteBlocks.Add(Entity.EntityId, m_block);
                    IMySlimBlock slimBlock = ((MyCubeBlock)m_block.ConstructionBlock).SlimBlock as IMySlimBlock;
                    Logging.Instance.WriteLine(string.Format("ADDING Nanite Factory: conid={0} physics={1} ratio={2}", Entity.EntityId, m_block.ConstructionBlock.CubeGrid.Physics == null, slimBlock.BuildLevelRatio));

                    //if (NaniteConstructionManager.NaniteSync != null)
                    //    NaniteConstructionManager.NaniteSync.SendNeedTerminalSettings(Entity.EntityId);
                }
            }
        }
Beispiel #15
0
        public NaniteLifeSupportTargets(NaniteConstructionBlock constructionBlock) : base(constructionBlock)
        {
            m_maxDistance   = NaniteConstructionManager.Settings.LifeSupportMaxDistance;
            m_targetTracker = new Dictionary <IMyPlayer, NaniteLifeSupportTarget>();

            m_o2RefillLevel   = NaniteConstructionManager.Settings.LifeSupportOxygenRefillLevel;
            m_o2RefillPerTick = NaniteConstructionManager.Settings.LifeSupportOxygenPerTick;

            m_h2RefillLevel   = NaniteConstructionManager.Settings.LifeSupportHydrogenRefillLevel;
            m_h2RefillPerTick = NaniteConstructionManager.Settings.LifeSupportHydrogenPerTick;

            m_energyRefillLevel   = NaniteConstructionManager.Settings.LifeSupportEnergyRefillLevel;
            m_energyRefillPerTick = NaniteConstructionManager.Settings.LifeSupportEnergyPerTick;

            m_healthRefillPerTick = NaniteConstructionManager.Settings.LifeSupportHealthPerTick;

            m_progressSoundEmitter = new MyEntity3DSoundEmitter((MyEntity)constructionBlock.ConstructionBlock);
            m_progressSound        = new MySoundPair("BlockMedicalProgress");

            connectedGasTanks = new List <IMyGasTank>();

            m_hasOxygen   = false;
            m_hasHydrogen = false;
        }
 public NaniteParticleManager(NaniteConstructionBlock block)
 {
     m_particles         = new List <NaniteParticle>();
     m_constructionBlock = block;
     m_updateCount       = 0;
 }
 //private NaniteConstructionBlock m_constructionBlock;
 public NaniteProjectionTargets(NaniteConstructionBlock constructionBlock) : base(constructionBlock)
 {
     m_count        = 0;
     m_targetBlocks = new Dictionary <IMySlimBlock, NaniteProjectionTarget>();
     m_maxDistance  = NaniteConstructionManager.Settings.ProjectionMaxBeaconDistance;
 }
Beispiel #18
0
 public NaniteGrinder(NaniteConstructionBlock constructionBlock, IMySlimBlock block, int waitTime, bool performanceFriendly) : base(constructionBlock, block, waitTime, m_grinderGrid, performanceFriendly, true)
 {
 }
Beispiel #19
0
 public abstract bool IsEnabled(NaniteConstructionBlock factory);
 public NaniteFloatingTargets(NaniteConstructionBlock constructionBlock) : base(constructionBlock)
 {
     m_targetTracker = new Dictionary <IMyEntity, NaniteFloatingTarget>();
     m_carryVolume   = NaniteConstructionManager.Settings.CleanupCarryVolume;
     m_maxDistance   = NaniteConstructionManager.Settings.CleanupMaxDistance;
 }