private void handleStateValidity() { try { List <IMyTerminalAction> actions = new List <IMyTerminalAction>(); MyAPIGateway.TerminalControls.GetActions <IMyUpgradeModule>(out actions); foreach (IMyTerminalAction action in actions) { //IO.log("Checking action '"+action.Id); if (action.Id.ToString() == "fire") { action.Enabled = isReadyToFire; } } List <IMyTerminalControl> controls = new List <IMyTerminalControl>(); MyAPIGateway.TerminalControls.GetControls <IMyUpgradeModule>(out controls); foreach (IMyTerminalControl action in controls) { //IO.log("Checking control '"+action.Id); if (action.Id.ToString() == "fire") { action.Enabled = isReadyToFire; } } } catch (Exception e) { IO.log(e.ToString()); } }
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 } }
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); }