void Start() { gridSystem = GridTerminalSystem; gridId = Me.CubeGrid.EntityId; if (string.IsNullOrWhiteSpace(turretGroup)) { turrets = GetBlocks <IMyLargeTurretBase>(useSubgrids); } else { turrets = GetBlocks <IMyLargeTurretBase>(turretGroup, useSubgrids); } wcTurrets = new WcPbApi(); if (string.IsNullOrWhiteSpace(rcName)) { rc = GetBlock <IMyRemoteControl>(); } else { rc = GetBlock <IMyRemoteControl>(rcName, useSubgrids); } if (rc == null) { throw new Exception("Remote control block not found."); } origin = rc.GetPosition(); if (receiveHelpMsgs) { helpListener = IGC.RegisterBroadcastListener("AttackDrone_" + commsId); helpListener.SetMessageCallback(""); } startRuntime = -1; }
public Program() { Runtime.UpdateFrequency = UpdateFrequency.None; try { api = new WcPbApi(); api.Activate(Me); debugPanels = new Dictionary <string, DebugPanel>(); InitDebugPanels(); DebugPanel debugLog = DebugPanelByName("log"); debugLog.Title = "Debug Log"; // The remote control block is the forward reference for this grid. I should probably change this to something else.... remoteControlBlock = GridTerminalSystem.GetBlockWithName("Remote Control") as IMyRemoteControl; situationalAwareness = new SituationalAwareness(api, Me, AccelerationFilterCoeff, DebugPanelByName("sitcon"), DebugPanelByName("track")); navigationSystems = new NavigationSystems(GridTerminalSystem, remoteControlBlock); motionController = new Autopilot(navigationSystems, DebugPanelByName("heading"), DebugPanelByName("thrust")); currentTime = 0; } catch (Exception e) { Echo($"*** Caught exception {e.Message}\n{e.StackTrace}"); } }
public void Setup(ExecutionContext context, string name) { Context = context; if (!WCAPI.Activate(Context.Program.Me)) { WCAPI = null; } IntelProvider.AddIntelMutator(this); GetParts(); ParseConfigs(); HoldFire(); }
public SituationalAwareness(WcPbApi api_, IMyTerminalBlock me_, float accelerationFilterCoeff_, DebugPanel sitconPanel_, DebugPanel trackPanel_) { api = api_; me = me_; accelerationFilterCoeff = accelerationFilterCoeff_; sitconPanel = sitconPanel_; trackPanel = trackPanel_; if (sitconPanel != null) { sitconPanel.Title = "All hostiles:"; } if (trackPanel != null) { trackPanel.Title = "Target track:"; } }
void Start() { gridSystem = GridTerminalSystem; gridId = Me.CubeGrid.EntityId; turrets = GetBlocks <IMyLargeTurretBase>(turretGroup, useSubgrids); wcTurrets = new WcPbApi(); try { if (!wcTurrets.Activate(Me)) { wcTurrets = null; } } catch { wcTurrets = null; } if (string.IsNullOrWhiteSpace(rcName)) { rc = GetBlock <IMyRemoteControl>(); } else { rc = GetBlock <IMyRemoteControl>(rcName, useSubgrids); } if (rc == null) { throw new Exception("Remote control block not found."); } gyros = new GyroControl(rc); origin = rc.GetPosition(); this.guns = new List <IMyUserControllableGun>(); List <IMyUserControllableGun> guns = GetBlocks <IMyUserControllableGun>(gunsGroup, useSubgrids); foreach (IMyUserControllableGun g in guns) { if (!(g is IMyLargeTurretBase)) { g.SetValueBool("Shoot", false); if (rocketMode != RocketMode.None) { IMySmallMissileLauncher m = g as IMySmallMissileLauncher; if (m != null) { rockets.Add(m); continue; } } this.guns.Add(g); } } if (receiveHelpMsgs) { helpListener = IGC.RegisterBroadcastListener("AttackDrone_" + commsId); helpListener.SetMessageCallback(""); } thrust = new ThrusterControl(rc, GetBlocks <IMyThrust>(thrustGroup)); maxAngle *= Math.PI / 180; startRuntime = -1; }
public void Update(TimeSpan timestamp, UpdateFrequency updateFlags) { runs++; if (WCAPI == null && runs % 12 == 0) { WCAPI = new WcPbApi(); if (WCAPI.Activate(Context.Program.Me)) { GetParts(); } else { WCAPI = null; } } TargetIntel = null; var canonicalTime = timestamp + IntelProvider.CanonicalTimeDiff; foreach (var turret in Turrets) { if (!turret.HasTarget) { continue; } var target = turret.GetTargetedEntity(); if (target.IsEmpty()) { continue; } if (target.Type != MyDetectedEntityType.SmallGrid && target.Type != MyDetectedEntityType.LargeGrid) { continue; } if (target.Relationship != MyRelationsBetweenPlayerAndBlock.Enemies) { continue; } var intelDict = IntelProvider.GetFleetIntelligences(timestamp); var key = MyTuple.Create(IntelItemType.Enemy, target.EntityId); if (intelDict.ContainsKey(key)) { turret.ResetTargetingToDefault(); continue; } TargetIntel = intelDict.ContainsKey(key) ? (EnemyShipIntel)intelDict[key] : new EnemyShipIntel(); } if (fireCounter > 0) { fireCounter--; } if (fireCounter == 0) { HoldFire(); } if (engageCounter > 0) { engageCounter--; } }