bool FuncTest(IMyWarhead block) { //Warhead //Interface name: IMyWarhead //Fields: bool IsCountingDown = block.IsCountingDown; float DetonationTime = block.DetonationTime; return(true); }
/// <summary> /// Gets actions for blocks implementing IMyWarhead. /// </summary> public static void GetWarheadActions(IMyTerminalBlock tBlock, List <IScrollableAction> actions) { IMyWarhead warhead = (IMyWarhead)tBlock; actions.Add(new BlockAction( () => $"Start Countdown", () => warhead.StartCountdown())); actions.Add(new BlockAction( () => "Stop Countdown", () => warhead.StopCountdown())); actions.Add(new BlockAction( () => "Detonate", () => warhead.Detonate())); }
private void SaveAndApply(IBlockConfiguration block, IMyWarhead warhead, Action <IMyWarhead> action) { if (block == null) { return; } if (!block.HasStyle) { block.SetStyle(nameof(IMyWarhead.IsArmed), warhead.IsArmed); block.SetStyle(nameof(IMyWarhead.DetonationTime), warhead.DetonationTime); } action(warhead); }
/** * Get the owner of a Warhead. */ private static bool GetPlayerByWarhead( IMyWarhead warhead, out IMyPlayer owner, out IMyFaction owningFaction) { if (warhead.OwnerId == 0) { long playerId = (warhead as MyCubeBlock).BuiltBy; owner = MyAPIGateway.Players.GetPlayerByID(playerId); owningFaction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(playerId); } else { long playerId = warhead.OwnerId; owner = MyAPIGateway.Players.GetPlayerByID(playerId); owningFaction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(playerId); } return owner != null || owningFaction != null; }
double GetClosestDistance(List <IMyWarhead> entities, IMyMotorStator reference) { IMyWarhead closestEntity = null; double closestDistance = 100; if (entities.Count() > 0) { foreach (var entity in entities) { var distance = Vector3D.Distance(reference.GetPosition(), entity.GetPosition()); if (distance < closestDistance) { closestDistance = distance; closestEntity = entity; } } } return(closestDistance); }
static bool IsDamagedByPlayerWarhead(IMyWarhead Warhead, out IMyPlayer Damager) { Damager = null; try { if (Warhead.OwnerId == 0) { Damager = MyAPIGateway.Players.GetPlayerByID((Warhead as MyCubeBlock).BuiltBy); AISessionCore.DebugWrite("Damage.IsDoneByPlayer", "Attempting to find damager by neutral warhead."); return(Damager != null); } else { Damager = MyAPIGateway.Players.GetPlayerByID(Warhead.OwnerId); AISessionCore.DebugWrite("Damage.IsDoneByPlayer", "Attempting to find damager by warhead owner."); return(Damager != null); } } catch (Exception Scrap) { AISessionCore.LogError("Damage.IsDoneByPlayer", new Exception("Check for neutral warheads crashed", Scrap)); return(false); } }
private void Restore(IBlockConfiguration block, IMyWarhead warhead) { warhead.IsArmed = block.GetBooleanStyle(nameof(IMyWarhead.IsArmed)); warhead.DetonationTime = block.GetSingleStyle(nameof(IMyWarhead.DetonationTime), Countdown); }
//Preps For Launch & Launches #region RFC Prep-For Launch Subroutine #RFC# /*================================================= * Function: RFC Function bar #RFC# * --------------------------------------- */ void PREP_FOR_LAUNCH(int INT) { Echo(INT + ""); MISSILE ThisMissile = MISSILES[INT]; ThisMissile.MissileMass = 0; ThisMissile.MissileThrust = 0; //Preps Battery For Launch var POWER_A = ThisMissile.POWER; if (ThisMissile.POWER != null && ThisMissile.POWER is IMyBatteryBlock) { POWER_A.ApplyAction("OnOff_On"); (POWER_A as IMyBatteryBlock).ChargeMode = ChargeMode.Discharge; ThisMissile.MissileMass += POWER_A.Mass; } //Removes Thrusters That Are Still on the same Grid As launcher List <IMyThrust> TemporaryThrust = new List <IMyThrust>(); TemporaryThrust.AddRange(ThisMissile.THRUSTERS); for (int i = 0; i < TemporaryThrust.Count; i++) { var item = TemporaryThrust[i]; if (item.CubeGrid != ThisMissile.GYRO.CubeGrid) { ThisMissile.THRUSTERS.Remove(item); continue; } } if (ThisMissile.THRUSTERS.Count == 0) { Lstrundata = "Missile Failed To Fire\nReason: No Detectable Thrusters On Missile Or Missile Still Attached To Launcher"; MISSILES.Remove(ThisMissile); return; } //Retrieves Largest Thrust Direction Dictionary <Vector3D, double> ThrustDict = new Dictionary <Vector3D, double>(); foreach (IMyThrust item in ThisMissile.THRUSTERS) { Vector3D Fwd = item.WorldMatrix.Forward; double Thrval = item.MaxEffectiveThrust; if (ThrustDict.ContainsKey(Fwd) == false) { ThrustDict.Add(Fwd, Thrval); } else { ThrustDict[Fwd] = ThrustDict[Fwd] + Thrval; } } List <KeyValuePair <Vector3D, double> > ThrustList = ThrustDict.ToList(); ThrustList.Sort((x, y) => y.Value.CompareTo(x.Value)); Vector3D ThrForward = ThrustList[0].Key; //Preps Thrusters For Launch (removes any not on grid) TemporaryThrust = new List <IMyThrust>(); TemporaryThrust.AddRange(ThisMissile.THRUSTERS); for (int i = 0; i < TemporaryThrust.Count; i++) { var item = TemporaryThrust[i]; //Retrieves Thrusters Only Going In The Forward if (item.WorldMatrix.Forward != ThrForward) { item.ApplyAction("OnOff_On"); ThisMissile.THRUSTERS.Remove(item); continue; } //Runs Std Operations item.ApplyAction("OnOff_On"); double ThisThrusterThrust = (item as IMyThrust).MaxThrust; (item as IMyThrust).ThrustOverride = (float)ThisThrusterThrust; RdavUtils.DiagTools.Diag_Plot(Me, ThisThrusterThrust); ThisMissile.MissileThrust += ThisThrusterThrust; ThisMissile.MissileMass += item.Mass; } // Start countdown of warhead for (int i = 0; i < ThisMissile.WARHEADS.Count; i++) { IMyWarhead warhead = ( IMyWarhead )ThisMissile.WARHEADS[i]; warhead.ApplyAction("StartCountdown"); } //Removes Any Warheads Not On The Grid List <IMyTerminalBlock> TemporaryWarheads = new List <IMyTerminalBlock>(); TemporaryWarheads.AddRange(ThisMissile.WARHEADS); for (int i = 0; i < ThisMissile.WARHEADS.Count; i++) { var item = TemporaryWarheads[i]; if (item.CubeGrid != ThisMissile.GYRO.CubeGrid) { ThisMissile.WARHEADS.Remove(item); continue; } ThisMissile.MissileMass += item.Mass; } //----------------------------------------------------- //Adds Additional Mass & Sets Accel (ovverrides If Possible) ThisMissile.MissileMass += ThisMissile.GYRO.Mass; ThisMissile.MissileMass += ThisMissile.MERGE.Mass; double number; if (double.TryParse(ThisMissile.GYRO.CustomData, out number)) { double.TryParse(ThisMissile.GYRO.CustomData, out ThisMissile.MissileMass); } ThisMissile.MissileAccel = ThisMissile.MissileThrust / ThisMissile.MissileMass; //Sets Grid Type ThisMissile.IsLargeGrid = ThisMissile.GYRO.CubeGrid.GridSizeEnum == MyCubeSize.Large; ThisMissile.FuseDistance = ThisMissile.IsLargeGrid ? 16 : 7; }