Пример #1
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            doSetup("Utility", 6, 60, MyEntityUpdateEnum.EACH_100TH_FRAME, MyEntityUpdateEnum.EACH_10TH_FRAME);
            prepareEmissives("ColorBand", 4);

            distanceMultiplier = 1;

            if (thisGrid.GridSizeEnum == MyCubeSize.Large)
            {
                distanceMultiplier = thisGrid.IsStatic ? 20 : 4;
            }

            double maxd = 0;

            foreach (var entry in Configuration.reactionMap)
            {
                EMPReaction es = entry.Value;
                maxd = Math.Max(maxd, es.MaxDistance * es.SameGridBoost);
            }

            double d = maxd * distanceMultiplier;

            scanRange = new BoundingBoxD(new Vector3D(-d, -d, -d), new Vector3D(d, d, d));
        }
Пример #2
0
 private bool empBlock(IMySlimBlock slimBlock, IMyTerminalBlock block, double distance, bool sameGrid, EMPReaction reaction, bool forceDamage, bool forceDestroy)
 {
     /*
      * if (reaction == null) {
      *      MyAPIGateway.Utilities.ShowNotification("Block "+block.CustomName+" pulled null reaction?!", 5000, MyFontEnum.Red);
      *      return false;
      * }
      * if (slimBlock == null) {
      *      MyAPIGateway.Utilities.ShowNotification("Block "+block.CustomName+" has null slimblock?!", 5000, MyFontEnum.Red);
      *      return false;
      * }
      * if (block == null) {
      *      MyAPIGateway.Utilities.ShowNotification("Block "+slimBlock.BlockDefinition+" has null terminal block?!", 5000, MyFontEnum.Red);
      *      return false;
      * }*/
     try {
         bool disabled = false;
         if ((slimBlock is IMyDestroyableObject) && (forceDamage || rand.Next(5) == 0))
         {
             disabled = damageBlock(slimBlock, block, distance, forceDestroy);
         }
         else
         {
             IMyFunctionalBlock func = block as IMyFunctionalBlock;
             //func.ApplyAction("OnOff_Off");
             func.Enabled = false;
             func.UpdateIsWorking();
             //MyAPIGateway.Utilities.ShowNotification("EMP'd (on/off) block "+block.CustomName+" @ "+distance, 5000, MyFontEnum.Red);
             disabled = true;                     //always successfully handled in the first cycle
         }
         if (disabled && !sameGrid && reaction.MaxDowntimeIfRemote >= 0)
         {
             blockReactivations.Add(new SavedTimedBlock(block, reaction));
         }
         reaction.triggerEffect(block, rand);
         return(disabled);
     }
     catch (Exception ex) {
         MyAPIGateway.Utilities.ShowNotification("Could not EMP block " + block.CustomName + ": " + ex.ToString(), 5000, MyFontEnum.Red);
         IO.log("Threw exception EMPing block " + block.CustomName + ": " + ex.ToString());
         return(true);                //shut down to avoid constantly throwing exceptions
     }
 }
Пример #3
0
        private bool affectEnemyBlocks()
        {
            bool done = true;

            scanArea = scanRange.TransformSlow(thisBlock.WorldMatrix);
            List <IMyEntity> entityList = null;

            lock (MyAPIGateway.Entities) {  // Scan for nearby entities (grids)
                entityList = MyAPIGateway.Entities.GetElementsInBox(ref scanArea);
            }

            if (entityList != null)
            {
                List <IMySlimBlock> gridBlocks = new List <IMySlimBlock>();
                foreach (IMyEntity entity in entityList)
                {
                    try {
                        if (entity is IMyCubeGrid)
                        {
                            IMyCubeGrid grid = entity as IMyCubeGrid;
                            if (isEnemyGrid(grid))
                            {
                                gridBlocks.Clear();
                                grid.GetBlocks(gridBlocks, b => b.FatBlock is IMyTerminalBlock && (b.FatBlock as IMyTerminalBlock).IsWorking && isEnemyBlock(b.FatBlock));
                                //MyAPIGateway.Utilities.ShowNotification("Found grid #"+i+" named "+grid.Name+" & "+grid.GetFriendlyName()+", ID="+grid.EntityId+"; size = "+grid.GridSizeEnum+", owners = "+grid.SmallOwners.ToString()+", grid elements = "+gridBlocks.ToString(), 5000, MyFontEnum.Red);
                                foreach (IMySlimBlock slim in gridBlocks)
                                {
                                    IMyTerminalBlock block    = slim.FatBlock as IMyTerminalBlock;
                                    EMPReaction      reaction = Configuration.getEMPReaction(block);
                                    if (reaction != null)
                                    {
                                        bool share = thisGrid == grid;
                                        if (rand.Next(100) >= (share ? reaction.ResistanceSameGrid : reaction.Resistance))
                                        {
                                            bool   inRange  = reaction.InfRangeSharedGrid;
                                            double distance = reaction.InfRangeSharedGrid ? 0 : Vector3D.Distance(thisBlock.GetPosition(), block.GetPosition());
                                            if (!inRange)
                                            {
                                                double d = reaction.MaxDistance;
                                                if (share)
                                                {
                                                    //MyAPIGateway.Utilities.ShowNotification("boosting range (from "+d+" by "+reaction.SameGridBoost+"x) due to grid sharing ("+emp_grid.EntityId+"/"+emp_grid.GridSizeEnum+" & "+grid.EntityId+"/"+grid.GridSizeEnum+") for block "+block.CustomName+" @ "+distance, 5000, MyFontEnum.Red);
                                                    d *= reaction.SameGridBoost;
                                                }
                                                else
                                                {
                                                    //MyAPIGateway.Utilities.ShowNotification("Not boosting range (from "+d+", using native "+distanceMultiplier+"x instead); no grid sharing ("+emp_grid.EntityId+"/"+emp_grid.GridSizeEnum+" & "+grid.EntityId+"/"+grid.GridSizeEnum+") for block "+block.CustomName+" @ "+distance, 5000, MyFontEnum.Red);
                                                    d *= distanceMultiplier;
                                                }
                                                inRange = distance < d;
                                            }
                                            if (inRange)
                                            {
                                                done &= empBlock(slim, block, distance, share, reaction, !(block is IMyFunctionalBlock), false);
                                            }
                                            else
                                            {
                                                //MyAPIGateway.Utilities.ShowNotification("Not EMPing block "+block.CustomName+" @ "+distance+"; out of range", 5000, MyFontEnum.Red);
                                            }
                                        }
                                        else if (reaction.Resistance < 100)
                                        {
                                            done = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex) {
                        //MyAPIGateway.Utilities.ShowNotification("Could not run EMP cycle: "+ex.ToString(), 5000, MyFontEnum.Red);
                        IO.log("Could not run EMP cycle: " + ex.ToString());
                    }
                }
            }
            return(done);
        }