void Setup() { _setupReturnCode = ReturnCode.None; _controller = null; _azimuthRotor = null; _elevationRotor = null; _camera = null; _extraRotors.Clear(); _tools.Clear(); _gridToToolDict.Clear(); _restAngles.Clear(); _group.GetBlocks(null, CollectBlocks); if (_controller == null) { _setupReturnCode |= ReturnCode.MissingController; } if (_azimuthRotor == null) { _setupReturnCode |= ReturnCode.MissingAzimuth; } if (_elevationRotor == null) { _setupReturnCode |= ReturnCode.MissingElevation; } if (_extraRotors.Count == 0) { _setupReturnCode |= ReturnCode.NoExtraRotors; } if (_camera == null) { _setupReturnCode |= ReturnCode.MissingCamera; } if (_tools.Count == 0) { _setupReturnCode |= ReturnCode.MissingTools; } }
public Program() { control = GridTerminalSystem.GetBlockWithName("Control") as IMyRemoteControl; visor = GridTerminalSystem.GetBlockWithName("Visor") as IMyCameraBlock; visor.EnableRaycast = true; for (int i = 0; i < 6; i++) { thruster.Add((Side)i, new List <IMyThrust>()); maxThrust.Add((Side)i, 0); } List <IMyThrust> thrust = new List <IMyThrust>(); GridTerminalSystem.GetBlocksOfType(thrust); allThruster = thrust; foreach (IMyThrust thr in thrust) { SortThruster(thr); thr.SetValueFloat("Override", 0); } List <IMyGyro> GyrosList = new List <IMyGyro>(); GridTerminalSystem.GetBlocksOfType(GyrosList); foreach (IMyGyro gyro in GyrosList) { gyro.GyroOverride = true; gyros.Add(new Gyroscope(gyro, control)); } SetGyros(0, 0, 0); GridTerminalSystem.GetBlocksOfType(grinder); IMyBlockGroup sensors = GridTerminalSystem.GetBlockGroupWithName("Sensor Grinder"); sensors.GetBlocksOfType(mainGrinderSensors); sensors = GridTerminalSystem.GetBlockGroupWithName("Sensor Collision"); sensors.GetBlocksOfType(mainCollisionSensors); List <IMyCargoContainer> container = new List <IMyCargoContainer>(); GridTerminalSystem.GetBlocksOfType(container); baseMass = control.CalculateShipMass().TotalMass; Echo("Init completed"); }
public Program() { this.camera = this.GridTerminalSystem.GetBlockWithName("Front Camera") as IMyCameraBlock; this.lcd = this.GridTerminalSystem.GetBlockWithName("LCD") as IMyTextPanel; if (this.camera == null) { Echo("Error finding camera"); return; } if (this.lcd == null) { Echo("Error finding LCD"); return; } Echo("Startup complete."); camera.EnableRaycast = true; this.Runtime.UpdateFrequency = UpdateFrequency.Update100; }
public string StatisticsForCurrentCamera() { string aResult = ""; IMyCameraBlock aCamera = mCameras[mCurrentCameraIndex]; double aDelta = aCamera.AvailableScanRange - mLastCanScan; aResult += String.Format("Camera Index: {0:00}/{1:00}\n Name: {2}\n CanScan [{3:0.0} km]: {4}\n ScanRange: {5:0.0} km\n Mass: {6}\nDelta: {7}\n\n", mCurrentCameraIndex + 1, mCameras.Count, aCamera.CustomName, DEFAULT_SCAN_RANGE / 1000, aCamera.CanScan(DEFAULT_SCAN_RANGE) ? 'Y' : 'N', aCamera.AvailableScanRange / 1000, aCamera.Mass, aDelta ); mLastCanScan = aCamera.AvailableScanRange; return(aResult); }
public void LookingGlassRaycast(IMyCameraBlock camera, TimeSpan localTime) { if (camera == null) { return; } double dist = RaycastDistanceMax; if (camera.RaycastDistanceLimit >= 0) { dist = Math.Min(camera.RaycastDistanceLimit, dist); } // ScanExtent and 10.f are to avoid accidentally overflowing distance limitations later in processing and floating point error respectively. dist -= ScanExtent + 10.0; // debugBuilder.AppendLine("LGR D=" + dist.ToString() + " L=" + camera.RaycastDistanceLimit.ToString()); var pos = camera.WorldMatrix.Forward * dist + camera.WorldMatrix.Translation; TryScanTarget(pos, localTime); }
public Program() { PrintForAllTerminals(""); // Configure this program to run both Once and every 100 update ticks Runtime.UpdateFrequency = UpdateFrequency.Update10; camera = GridTerminalSystem.GetBlockWithName(CAM_NAME) as IMyCameraBlock; if (camera != null) { camera.EnableRaycast = true; } else { PrintForAllTerminals($"Не удалось найти камеру с именем {CAM_NAME}"); } rotor = GridTerminalSystem.GetBlockWithName(ROTOR_NAME) as IMyMotorStator; if (rotor == null) { PrintForAllTerminals($"Не удалось ротор с именем {ROTOR_NAME}"); } }
public void Main(string argument, UpdateType updateSource) { IMyCameraBlock cam = GridTerminalSystem.GetBlockWithName("TestCam") as IMyCameraBlock; if (cam != null) { cam.EnableRaycast = true; MyDetectedEntityInfo shit = cam.Raycast(new Vector3D(1, 1, 1)); if (shit.HitPosition.HasValue) { double distance = Vector3D.Distance(shit.HitPosition.Value, cam.GetPosition()); DjConfig.lastVal = distance; DjConfig.isRip = !shit.HitPosition.HasValue; } StringBuilder msg = new StringBuilder(); msg .Append($"Distance: {String.Format("{0:0,0.##}", DjConfig.lastVal)}m\n") .Append($"IsRip: {DjConfig.isRip}"); Echo(msg.ToString()); } }
// Start program public void Main(string argument) { int SCAN_DISTANCE = 1000; // Distance we can scan int SCAN_DISTANCE_MIN = 100; // Smallest acceptable distance // Find a working target painter IMyCameraBlock targetPainter = FindBlock <IMyCameraBlock>("targetPainter_Camera"); if (targetPainter == null) { return; // Couldn't find target painter } targetPainter.EnableRaycast = true; // Find a working display IMyTextPanel panel = FindBlock <IMyTextPanel>("targetPainter_Display"); if (panel == null) { return; // Couldn't find a display } // Try to scan at max distance but settle for smaller value MyDetectedEntityInfo data; while (SCAN_DISTANCE > SCAN_DISTANCE_MIN) { if (targetPainter.CanScan(SCAN_DISTANCE)) { data = targetPainter.Raycast(SCAN_DISTANCE, 0, 0); SaveCoords(data, panel); return; } SCAN_DISTANCE /= 2; } }
public void SubConstructor() { //DEBUG ATTACHMENTS P = this; //Timing Runtime.UpdateFrequency = UpdateFrequency.Update1 | UpdateFrequency.Update100; ingameTime = new IngameTime(); //Generic Inits gridTerminalSystemUtils = new GridTerminalSystemUtils(Me, GridTerminalSystem); reference = GridTerminalSystem.GetBlockWithName(REFERENCENAME) as IMyShipController; targetingCamera = GridTerminalSystem.GetBlockWithName(TARGETCAMNAME) as IMyCameraBlock; textOut = GridTerminalSystem.GetBlockWithName(TEXTOUTNAME) as IMyTextPanel; monoOut = GridTerminalSystem.GetBlockWithName(MonoLCDName) as IMyTextPanel; //Module Inits //entityTracking = new EntityTracking_Module(gridTerminalSystemUtils, reference, targetingCamera); //autopilotModule = new Autopilot_Module(gridTerminalSystemUtils, reference, ingameTime, gyroPidSettings, thrustPidSettings, entityTracking); scheduler = new Scheduler(); drawingLib = new MonospaceDrawingLib(175, 175, Color.Black); drawingLib.onRenderDone = OnRenderDone; drawingLib.AddRenderTask(drawingLib.Generate(), OnRenderDone); }
public Program() { Runtime.UpdateFrequency = UpdateFrequency.Update1; Cam = GridTerminalSystem.GetBlockWithName("cam") as IMyCameraBlock; lcd = GridTerminalSystem.GetBlockWithName("lcd") as IMyTextPanel; }
Program() { Runtime.UpdateFrequency = UpdateFrequency.Update1; cameras = new List <IMyCameraBlock>(); targets = new List <MyDetectedEntityInfo>(); curTarget = NOTHING; tPanel = GridTerminalSystem.GetBlockWithName("LCD Panel") as IMyTextPanel; max = cameras.Count() > 0 ? cameras[0].RaycastConeLimit : 45; x = 0; //-1*max; y = 0; //-1*max; for (int i = 0; i < 6; i++) { string preffix = ""; if (i == 1) { preffix = "FWD "; } else if (i == 2) { preffix = "BWD "; } else if (i == 3) { preffix = "LFT "; } else if (i == 4) { preffix = "RIG "; } else if (i == 5) { preffix = "TOP "; } else if (i == 6) { preffix = "BOT "; } IMyMotorStator XRot = GridTerminalSystem.GetBlockWithName(preffix + "Targetting Ray/Pitch Rotor") as IMyMotorStator; //Targetting Ray/Pitch Rotor IMyMotorStator YRot = GridTerminalSystem.GetBlockWithName(preffix + "Targetting Ray/Yaw Rotor") as IMyMotorStator; //Targetting Ray/Yaw Rotor IMyShipController Cont = GridTerminalSystem.GetBlockWithName(preffix + "Targetting Ray/Remote") as IMyShipController; //Targetting Ray/Remote IMyCameraBlock Cam = GridTerminalSystem.GetBlockWithName(preffix + "Targetting Ray/Camera") as IMyCameraBlock; //Targetting Ray/Camera if (XRot == null || YRot == null || Cont == null || Cam == null) { if (XRot == null && YRot == null && Cont == null && Cam == null) { continue; } if (XRot == null) { Echo("XRot\n"); } if (YRot == null) { Echo("YRot\n"); } if (Cont == null) { Echo("Cont\n"); } if (Cam == null) { Echo("Cam\n"); } acSens.Add(new ActiveSensor(null, null, null, null)); } else { acSens.Add(new ActiveSensor(Cont, Cam, XRot, YRot)); } } GridTerminalSystem.GetBlocksOfType <IMyCameraBlock>(cameras); foreach (IMyCameraBlock cam in cameras) { cam.EnableRaycast = true; } foreach (ActiveSensor sens in acSens) { for (int i = 0; i < cameras.Count(); i++) { if (sens.Cam == null) { continue; } if (sens.Cam.Equals(cameras[i])) { cameras.RemoveAt(i); break; } } } }
public IEnumerator <bool> Init() { rc = GridTerminalSystem.GetBlockWithName(RC_Name) as IMyShipController; lcd = new Lcd(this); Echo("lcd loaded."); Echo("[|..........]"); yield return(true); sensor = new Sensor(rc, this); Echo("sensor loaded."); Echo("[||.........]"); yield return(true); wheel = new WheelControl(rc, this); Echo("wheel loaded."); Echo("[|||........]"); yield return(true); downforce = new Downforce(rc, this, DOWNFORCENAME); Echo("downforce loaded."); Echo("[||||.......]"); yield return(true); stopwatch = new Stopwatch(rc); Echo("stopwatch loaded."); Echo("[|||||......]"); yield return(true); logo = new Logo(this); Echo("logo loaded."); Echo("[||||||.....]"); yield return(true); transponder = new Transponder(this, PERSONSENSORNAME, ANTENNATAG); Echo("transponder loaded."); Echo("[|||||||....]"); yield return(true); lights = new Lights(rc, this, REARLIGHTGROUPNAME); Echo("lights loaded."); Echo("[||||||||...]"); yield return(true); gyroControl = new GyroControl(this, rc); Echo("gyrocontrol loaded."); Echo("[|||||||||..]"); yield return(true); IMyCameraBlock cam = GridTerminalSystem.GetBlockWithName(CAMERANAME) as IMyCameraBlock; surfaceScanner = new SurfaceScanner(cam, rc); Echo("surface scanner loaded"); Echo("[||||||||||.]"); yield return(true); dynamicCOM = new DynamicCOM(rc, this); Echo("DynamicCOM loaded"); Echo("[|||||||||||]"); Loaded = true; }
public double test(IMyCameraBlock cam, MyDetectedEntityInfo shit) { double distance = Vector3D.Distance(shit.HitPosition.Value, cam.GetPosition()); return(distance); }
public void SetCamera(IMyCameraBlock Camera) { this.Camera = Camera; Camera.EnableRaycast = true; }
public Program() { Runtime.UpdateFrequency = UpdateFrequency.Update1; #region serializer nameSerializer.AddValue("MAINCAMERANAME", x => x, "AimCamera"); nameSerializer.AddValue("PROJECTORNAME", x => x, "Proj"); nameSerializer.AddValue("LEADPROJECTORNAME", x => x, "LeadProj"); nameSerializer.AddValue("COCKPITNAME", x => x, "Cockpit"); nameSerializer.AddValue("MISSILECONTROLLER", x => x, "MissileController"); parameterSerializer.AddValue("detectionRange", x => double.Parse(x), 1000); parameterSerializer.AddValue("projectionDistanceFromCockpit", x => double.Parse(x), 30); parameterSerializer.AddValue("projectionOffsetX", x => int.Parse(x), 0); parameterSerializer.AddValue("projectionOffsetY", x => int.Parse(x), 0); parameterSerializer.AddValue("projectionOffsetZ", x => int.Parse(x), 0); string customDat = Me.CustomData; nameSerializer.FirstSerialization(ref customDat); parameterSerializer.FirstSerialization(ref customDat); Me.CustomData = customDat; nameSerializer.DeSerialize(Me.CustomData); parameterSerializer.DeSerialize(Me.CustomData); #endregion cameras = new List <IMyCameraBlock>(); GridTerminalSystem.GetBlocksOfType(cameras); foreach (var cam in cameras) { cam.EnableRaycast = true; } mainCam = GridTerminalSystem.GetBlockWithName(MAINCAMERANAME) as IMyCameraBlock; if (mainCam == null) { throw new Exception($"No camerablock named \"{MAINCAMERANAME}\""); } cockpit = GridTerminalSystem.GetBlockWithName(COCKPITNAME) as IMyShipController; if (cockpit == null) { throw new Exception($"No cockpit named \"{COCKPITNAME}\""); } var proj = GridTerminalSystem.GetBlockWithName(PROJECTORNAME) as IMyProjector; var leadproj = GridTerminalSystem.GetBlockWithName(LEADPROJECTORNAME) as IMyProjector; var gunList = new List <IMyUserControllableGun>(); GridTerminalSystem.GetBlocksOfType(gunList, x => x is IMySmallGatlingGun); guns = new GunSequencer(gunList); if (proj != null) { projector = new ProjectorVisualization(proj, projectionOffset); } if (leadproj != null) { leadProjector = new ProjectorVisualization(leadproj, projectionOffset); } missileManager = GridTerminalSystem.GetBlockWithName(MISSILECONTROLLER) as IMyProgrammableBlock; autoAim = null; DisposeAuto(); random = new Random(); }
public TargetFuncs(Program par, IMyCameraBlock cam) { parent = par; visor = cam; }
public void Add(IMyCameraBlock cam) { cam.ApplyAction("OnOff_On"); cam.EnableRaycast = true; group.Add(cam); }
bool CollectBlocks(IMyTerminalBlock b) { if (!b.IsSameConstructAs(_p.Me)) { return(false); } var rotor = b as IMyMotorStator; if (rotor != null) { ParseRotorIni(rotor); if (StringExtensions.Contains(b.CustomName, _p.AzimuthName)) { if (_azimuthRotor != null) { _extraRotors.Add(rotor); } else { _azimuthRotor = rotor; } } else if (StringExtensions.Contains(b.CustomName, _p.ElevationName)) { if (_elevationRotor != null) { _extraRotors.Add(rotor); } else { _elevationRotor = rotor; } } else { _extraRotors.Add(rotor); } } var cam = b as IMyCameraBlock; if (cam != null) { if (_camera != null) { _tools.Add(cam); } else { _camera = cam; } _gridToToolDict[cam.CubeGrid] = cam; } var tcb = b as IMyTurretControlBlock; if (tcb != null) { if (_controller != null) { _setupReturnCode |= ReturnCode.MultipleTurretControllers; } else { _controller = tcb; } } var func = b as IMyFunctionalBlock; if (func != null) { if (!(func is IMyLargeTurretBase) && (func is IMyUserControllableGun || func is IMyLightingBlock || func is IMyShipToolBase || func is IMyShipConnector)) { _tools.Add(func); _gridToToolDict[func.CubeGrid] = func; } } return(false); }
private void FirstTimeSetup(IMyRemoteControl rc) { try { RC1 = rc; myGridTerminal.GetBlocksOfType <IMyOreDetector>(oreDetectors, b => b.CubeGrid == RC1.CubeGrid); myGridTerminal.GetBlocksOfType <IMyCameraBlock>(cameraBlocks, b => b.CubeGrid == RC1.CubeGrid); myGridTerminal.GetBlocksOfType <IMyBatteryBlock>(batteryBlocks, b => b.CubeGrid == RC1.CubeGrid); myGridTerminal.GetBlocksOfType <IMyRadioAntenna>(RadioAntennas, b => b.CubeGrid == RC1.CubeGrid); if (cameraBlocks.Count > 0) { cameraBlock = cameraBlocks[0]; } myGridTerminal.GetBlocksOfType(mySmallMissiles, b => b.CubeGrid == RC1.CubeGrid); myGridTerminal.GetBlocksOfType(mySmallGatlings, b => b.CubeGrid == RC1.CubeGrid); myGridTerminal.GetBlocksOfType(myLargeTurrets, b => b.CubeGrid == RC1.CubeGrid); } catch (Exception e) { print(e.Message); } try { List <IMyTerminalBlock> TEMP_CON = new List <IMyTerminalBlock>(); myGridTerminal.GetBlocksOfType <IMyShipConnector>(TEMP_CON, b => b.CubeGrid == RC1.CubeGrid && b.CustomName.Contains("Ejector") == false); CONNECTOR1 = TEMP_CON[0] as IMyShipConnector; } catch { } try { List <IMyTerminalBlock> TEMP_GYRO = new List <IMyTerminalBlock>(); myGridTerminal.GetBlocksOfType <IMyGyro>(TEMP_GYRO, b => b.CubeGrid == RC1.CubeGrid); GYRO = TEMP_GYRO[0] as IMyGyro; } catch { } //Initialising Dedicated Cargo try { myGridTerminal.GetBlocksOfType <IMyCargoContainer>(Cargo, b => b.CubeGrid == RC1.CubeGrid); } catch { } //Gathers Antennae try { List <IMyTerminalBlock> TEMP = new List <IMyTerminalBlock>(); myGridTerminal.GetBlocksOfType <IMyRadioAntenna>(TEMP, b => b.CubeGrid == RC1.CubeGrid); RADIO = TEMP[0] as IMyRadioAntenna; RADIO.SetValue <long>("PBList", RC1.EntityId); RADIO.EnableBroadcasting = true; RADIO.Enabled = true; } catch { } //GathersControllers try { myGridTerminal.GetBlocksOfType <IMyShipController>(CONTROLLERS, b => b.CubeGrid == RC1.CubeGrid); } catch { } //Gathers Director Turret try { myGridTerminal.GetBlocksOfType <IMyLargeTurretBase>(DIRECTORS, b => b.CubeGrid == RC1.CubeGrid); } catch { } //Gathers Drills try { myGridTerminal.GetBlocksOfType <IMyShipDrill>(SHIP_DRILLS, b => b.CubeGrid == RC1.CubeGrid); } catch { } //Gathers Directional Weaponry try { myGridTerminal.GetBlocksOfType <IMyUserControllableGun>(DIRECTIONAL_FIRE, (block => ( block.GetType().Name == "MySmallMissileLauncher" || block.GetType().Name == "MySmallGatlingGun" || block.GetType().Name == "MySmallMissileLauncherReload" ) && block.CubeGrid == RC1.CubeGrid) ); //Collects the directional weaponry (in a group) } catch { } //Runs Thruster Setup try { CollectAndFire2(new Vector3D(), 0, 0, RC1.GetPosition(), RC1); for (int j = 0; j < CAF2_THRUST.Count; j++) { CAF2_THRUST[j].SetValue <float>("Override", 0.0f); CAF2_THRUST[j].ApplyAction("OnOff_On"); } } catch { } }
public void Main(string argument, UpdateType updateSource) { // The main entry point of the script, invoked every time // one of the programmable block's Run actions are invoked, // or the script updates itself. The updateSource argument // describes where the update came from. Be aware that the // updateSource is a bitfield and might contain more than // one update type. // // The method itself is required, but the arguments above // can be removed if not needed. if (firstrun) { firstrun = false; List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocks(blocks); foreach (var block in blocks) { if (block is IMyCameraBlock)//&& block.CustomName.Contains("Scanner Camera")) { cameras.Add((IMyCameraBlock)block); IMyCameraBlock cam = (IMyCameraBlock)block; cam.EnableRaycast = true; } if (block is IMyTextPanel && block.CustomName == "Norm Display") { lcd = (IMyTextPanel)block; } if (block is IMyTextPanel && block.CustomName == "Enemy Display") { enemyDisp = (IMyTextPanel)block; } } Echo("end setup Cameras count - " + cameras.Count); } sb.Clear(); foreach (var camera in cameras) { Echo("wrf"); if (camera == null) { continue; } if (camera.CanScan(SCAN_DISTANCE)) { info = camera.Raycast(SCAN_DISTANCE, PITCH, YAW); } else { info = new MyDetectedEntityInfo(); } //sb.Clear(); Echo(camera.EnableRaycast.ToString()); Echo(camera.AvailableScanRange.ToString()); if (sb == null) { continue; } if (info.IsEmpty()) { continue; } sb.AppendLine(); sb.Append(camera.CustomName); sb.AppendLine(); sb.Append("EntityID: " + info.EntityId); sb.AppendLine(); sb.Append("Name: " + info.Name); sb.AppendLine(); sb.Append("Type: " + info.Type); sb.AppendLine(); sb.Append("Velocity: " + info.Velocity.ToString("0.000")); sb.AppendLine(); sb.Append("Relationship: " + info.Relationship); sb.AppendLine(); sb.Append("Size: " + info.BoundingBox.Size.ToString("0.000")); sb.AppendLine(); sb.Append("Position: " + info.Position.ToString("0.000")); if (info.HitPosition.HasValue) { int index = detectedEnemies.FindIndex(f => f.EntityId == info.EntityId); if (index >= 0) { Echo("already have that enemy grid, skiping"); } else { detectedEnemies.Add(info); } } sb.AppendLine(); sb.Append("Range: " + camera.AvailableScanRange.ToString()); sb.AppendLine(); foreach (var enem in detectedEnemies) { enemies.AppendLine(); enemies.Append(enem.Name); enemies.AppendLine(); enemies.Append("Hit: " + info.HitPosition.Value.ToString("0.000")); enemies.AppendLine(); enemies.Append("Distance: " + Vector3D.Distance(camera.GetPosition(), info.HitPosition.Value).ToString("0.00")); enemies.AppendLine(); } } lcd.WriteText(sb.ToString()); enemyDisp.WriteText(enemies.ToString()); sb.Clear(); enemies.Clear(); }
void RangeFinder() { targetLog.Clear(); IMyCameraBlock lidar = GetCameraWithMaxRange(LIDARS); MyDetectedEntityInfo TARGET = lidar.Raycast(lidar.AvailableScanRange); if (!TARGET.IsEmpty() && TARGET.HitPosition.HasValue) { foreach (var block in ALARMS) { block.Play(); } if (TARGET.Type == MyDetectedEntityType.Planet) { Vector3D hitPosition = (Vector3D)TARGET.HitPosition; Vector3D safetyOffset = Vector3D.Normalize(REMOTE.CubeGrid.WorldVolume.Center - hitPosition) * planetAtmosphereRange; Vector3D safeJumpPosition = hitPosition + safetyOffset; REMOTE.ClearWaypoints(); REMOTE.AddWaypoint(safeJumpPosition, selectedPlanet); double distance = Vector3D.Distance(REMOTE.CubeGrid.WorldVolume.Center, safeJumpPosition); double maxDistance = GetMaxJumpDistance(JUMPERS[0]); if (maxDistance != 0 && distance != 0) { JUMPERS[0].SetValueFloat("JumpDistance", (float)(distance / maxDistance * 100d)); } targetPosition = safeJumpPosition; targetLog.Append("Safe Dist. for: ").Append(selectedPlanet).Append("\n"); string safeJumpGps = $"GPS:Safe Jump Pos:{Math.Round(safeJumpPosition.X)}:{Math.Round(safeJumpPosition.Y)}:{Math.Round(safeJumpPosition.Z)}"; targetLog.Append(safeJumpGps).Append("\n"); targetLog.Append("Atmo. Dist.: ").Append(distance.ToString("0.0")).Append("\n"); double targetDiameter = Vector3D.Distance(TARGET.BoundingBox.Min, TARGET.BoundingBox.Max); targetLog.Append("Diameter: ").Append(targetDiameter.ToString("0.0")).Append("\n"); double targetRadius = Vector3D.Distance(TARGET.Position, hitPosition); targetLog.Append("Radius: ").Append(targetRadius.ToString("0.0")).Append("\n"); double targetGroundDistance = Vector3D.Distance(REMOTE.CubeGrid.WorldVolume.Center, hitPosition); targetLog.Append("Ground Dist.: ").Append(targetGroundDistance.ToString("0.0")).Append("\n"); double targetAtmoHeight = Vector3D.Distance(hitPosition, safeJumpPosition); targetLog.Append("Atmo. Height: ").Append(targetAtmoHeight.ToString("0.0")).Append("\n"); } else if (TARGET.Type == MyDetectedEntityType.Asteroid) { Vector3D hitPosition = (Vector3D)TARGET.HitPosition; REMOTE.ClearWaypoints(); REMOTE.AddWaypoint(hitPosition, "Asteroid"); double distance = Vector3D.Distance(REMOTE.CubeGrid.WorldVolume.Center, hitPosition); double maxDistance = GetMaxJumpDistance(JUMPERS[0]); if (maxDistance != 0d && distance != 0d) { JUMPERS[0].SetValueFloat("JumpDistance", (float)(distance / maxDistance * 100d)); } targetPosition = hitPosition; string safeJumpGps = $"GPS:Asteroid:{Math.Round(hitPosition.X)}:{Math.Round(hitPosition.Y)}:{Math.Round(hitPosition.Z)}"; targetLog.Append(safeJumpGps).Append("\n"); targetLog.Append("Dist.: ").Append(distance.ToString("0.0")).Append("\n"); double targetDiameter = Vector3D.Distance(TARGET.BoundingBox.Min, TARGET.BoundingBox.Max); targetLog.Append("Diameter: ").Append(targetDiameter.ToString("0.0")).Append("\n"); } else if (IsNotFriendly(TARGET.Relationship)) { Vector3D hitPosition = (Vector3D)TARGET.HitPosition; Vector3D safetyOffset = Vector3D.Normalize(REMOTE.CubeGrid.WorldVolume.Center - hitPosition) * enemySafeDistance; Vector3D safeJumpPosition = hitPosition + safetyOffset; REMOTE.ClearWaypoints(); REMOTE.AddWaypoint(safeJumpPosition, TARGET.Name); double distance = Vector3D.Distance(REMOTE.CubeGrid.WorldVolume.Center, safeJumpPosition); double maxDistance = GetMaxJumpDistance(JUMPERS[0]); if (maxDistance != 0d && distance != 0d) { JUMPERS[0].SetValueFloat("JumpDistance", (float)(distance / maxDistance * 100d)); } targetPosition = safeJumpPosition; string safeJumpGps = $"GPS:Safe Jump Pos:{Math.Round(safeJumpPosition.X)}:{Math.Round(safeJumpPosition.Y)}:{Math.Round(safeJumpPosition.Z)}"; targetLog.Append(safeJumpGps).Append("\n"); targetLog.Append("Name: ").Append(TARGET.Name).Append("\n"); double targetDistance = Vector3D.Distance(REMOTE.CubeGrid.WorldVolume.Center, hitPosition); targetLog.Append("Dist: ").Append(targetDistance.ToString("0.0")).Append("\n"); double targetDiameter = Vector3D.Distance(TARGET.BoundingBox.Min, TARGET.BoundingBox.Max); targetLog.Append("Diameter: ").Append(targetDiameter.ToString("0.0")).Append("\n"); } else { Vector3D hitPosition = (Vector3D)TARGET.HitPosition; Vector3D safetyOffset = Vector3D.Normalize(REMOTE.CubeGrid.WorldVolume.Center - hitPosition) * friendlySafeDistance; Vector3D safeJumpPosition = hitPosition + safetyOffset; REMOTE.ClearWaypoints(); REMOTE.AddWaypoint(safeJumpPosition, TARGET.Name); double distance = Vector3D.Distance(REMOTE.CubeGrid.WorldVolume.Center, safeJumpPosition); double maxDistance = GetMaxJumpDistance(JUMPERS[0]); if (maxDistance != 0d && distance != 0d) { JUMPERS[0].SetValueFloat("JumpDistance", (float)(distance / maxDistance * 100d)); } targetPosition = safeJumpPosition; string safeJumpGps = $"GPS:Safe Jump Pos:{Math.Round(safeJumpPosition.X)}:{Math.Round(safeJumpPosition.Y)}:{Math.Round(safeJumpPosition.Z)}"; targetLog.Append(safeJumpGps).Append("\n"); targetLog.Append("Name: ").Append(TARGET.Name).Append("\n"); double targetDistance = Vector3D.Distance(REMOTE.CubeGrid.WorldVolume.Center, hitPosition); targetLog.Append("Dist: ").Append(targetDistance.ToString("0.0")).Append("\n"); double targetDiameter = Vector3D.Distance(TARGET.BoundingBox.Min, TARGET.BoundingBox.Max); targetLog.Append("Diameter: ").Append(targetDiameter.ToString("0.0")).Append("\n"); } } else { targetLog.Append("Nothing Detected!\n"); } }
public bool TryScan() { bool bFoundSomething = false; foreach (var tb in blocks) { camera = tb as IMyCameraBlock; if (camera == null) { continue; } if (camera.CanScan(SCAN_DISTANCE, NEXTPITCH, NEXTYAW)) { info = camera.Raycast(SCAN_DISTANCE, NEXTPITCH, NEXTYAW); quadrant++; if (!info.IsEmpty()) { bFoundSomething = true; SCAN_DISTANCE = Vector3D.Distance(camera.GetPosition(), info.Position); } if (NEXTPITCH == 0 && NEXTYAW == 0) { // no reason to rotate about 'center', so skipp to next scan PITCH = SCAN_MINIMUMADJUST; YAW = SCAN_MINIMUMADJUST; quadrant = 0; } if (quadrant > 3) { quadrant = 0; YAW += Math.Abs(YAW / SCAN_CENTER_SCALE_FACTOR) + SCAN_MINIMUMADJUST; if (Math.Abs(YAW) > YAWSCANRANGE) { // end of line. move to next line. quadrant = 0; YAW = 0; PITCH += Math.Abs(PITCH / SCAN_CENTER_SCALE_FACTOR) + SCAN_MINIMUMADJUST; } if (Math.Abs(PITCH) > PITCHSCANRANGE) { // end of scan box.. restart at 'center' PITCH = 0; YAW = 0; quadrant = 0; if (!bFoundSomething) // nothing found { // scan further SCAN_DISTANCE *= SCAN_SCALE_ON_MISS; // scale distance to go further. } bFoundSomething = false; } } switch (quadrant) { case 0: NEXTPITCH = PITCH; NEXTYAW = YAW; break; case 1: NEXTPITCH = -PITCH; NEXTYAW = YAW; break; case 2: NEXTPITCH = PITCH; NEXTYAW = -YAW; break; case 3: NEXTPITCH = -PITCH; NEXTYAW = -YAW; break; } } } return(bFoundSomething); }
void Main(string arg, UpdateType uType) { if (uType == UpdateType.Update1) { if (switchConnector) { foreach (var torpedo in Torpedos) { torpedo.SwitchConnectorLock(); } switchConnector = false; } Tick++; radar.Update(); lcd.WriteText("LOCKED: " + radar.Locked, false); lcd.WriteText("\nTarget: " + radar.CurrentTarget.Name + ", tick: " + radar.LastLockTick, true); lcd.WriteText("\nDistance: " + Math.Round(radar.TargetDistance), true); lcd.WriteText("\nVelocity: " + Math.Round(radar.CurrentTarget.Velocity.Length()), true); if (radar.Locked) { arta.AimCannons(radar.correctedTargetLocation, radar.CurrentTarget.Velocity); } foreach (Torpedo t in Torpedos) { if (t.status == 2) { t.Update(radar.CurrentTarget, CENTER_SHOT ? radar.CurrentTarget.Position : radar.T, cockpit.GetPosition(), cockpit.WorldMatrix.Forward); } } if (WolfPack) { if ((Tick - WolfPackStart + 1) % WOLF_PACK_WELDING_TIME == 0) { CleanGarbage(); InitializeTorpedos(); } if ((radar.Locked) && ((Tick - WolfPackStart - 1) % WOLF_PACK_WELDING_TIME == 0)) { foreach (Torpedo t in Torpedos) { Echo("\nTry Launch: "); Echo("\nWPI: " + WolfPackIndex); if (t.status == 1) { WolfPackIndex--; t.Launch(WolfPackDelays[WolfPackIndex]); break; } } if (WolfPackIndex <= 0) { WolfPack = false; } } } Echo("Runtime: " + Runtime.LastRunTimeMs); } else { switch (arg) { case "Lock": radar.Lock(true, 5000); if (radar.Locked) { arta.AimPoint = radar.CurrentTarget.Position; //sound.Play(); //sound.Play(); LASER_GUIDED = false; Runtime.UpdateFrequency = UpdateFrequency.Update1; } else { lcd.WriteText("NO TARGET", false); Runtime.UpdateFrequency = UpdateFrequency.None; } break; case "Laser": LASER_GUIDED = true; Runtime.UpdateFrequency = UpdateFrequency.Update1; break; case "CenterShot": CENTER_SHOT = !CENTER_SHOT; break; case "Init": CleanGarbage(); InitializeTorpedos(); break; case "SpotterCam": SpotterCam = gts.GetBlockWithName("SpotterCam") as IMyCameraBlock; if (SpotterCam != null) { SpotterCam.EnableRaycast = true; Echo("SpotterCam detected"); } break; case "Spot": if (SpotterCam != null) { Echo("Spotting"); MyDetectedEntityInfo spotterInfo = SpotterCam.Raycast(5000, 0, 0); if (!spotterInfo.IsEmpty()) { Echo("Target Spotted"); radar.correctedTargetLocation = spotterInfo.Position; radar.Lock(); if (radar.Locked) { Echo("Target Locked"); Runtime.UpdateFrequency = UpdateFrequency.Update1; /* sound.Play(); * sound.Stop(); * sound.Play(); * sound.Stop(); */ LASER_GUIDED = false; } } } break; case "Stop": radar.StopLock(); Runtime.UpdateFrequency = UpdateFrequency.None; break; case "Launch": if (radar.Locked) { foreach (Torpedo t in Torpedos) { Echo("\nTry Launch: "); if (t.status == 1) { Echo("1 go"); t.Launch(); break; } } } else { Echo("No Target Lock"); } break; case "Test": Echo("\n Test:" + VerticalDelay(5000.0f, 1700.0f, 300)); break; case "CCT": Runtime.UpdateFrequency = UpdateFrequency.Update1; arta.tensor_calculation = true; arta.tensor_calc_step = 0; break; case "Pack": if (radar.Locked) { WolfPackDelays.Clear(); WolfPackDelays.Add(LAUNCH_DELAY); for (int x = 0; x < WOLF_PACK_COUNT - 1; x++) { WolfPackDelays.Add(VerticalDelay((float)radar.TargetDistance, (float)(WOLF_PACK_WELDING_TIME - WOLF_PACK_INTERVAL) * 1.666667f, WolfPackDelays[WolfPackDelays.Count - 1])); } WolfPack = true; WolfPackStart = Tick; WolfPackIndex = WOLF_PACK_COUNT; } break; default: break; } } }
public Camera(GridDraw grid, IMyCameraBlock cam) { Grid = grid; Cam = cam; }
string camerasensorsInit(IMyTerminalBlock orientationBlock) { cameraForwardList.Clear(); cameraBackwardList.Clear(); cameraDownList.Clear(); cameraUpList.Clear(); cameraLeftList.Clear(); cameraRightList.Clear(); cameraAllList.Clear(); if (orientationBlock == null) { return("\nCameras:No OrientationBlock"); } GridTerminalSystem.GetBlocksOfType <IMyCameraBlock>(cameraAllList, (x1 => x1.CubeGrid == Me.CubeGrid)); Matrix fromGridToReference; orientationBlock.Orientation.GetMatrix(out fromGridToReference); Matrix.Transpose(ref fromGridToReference, out fromGridToReference); for (int i = 0; i < cameraAllList.Count; ++i) { if (cameraAllList[i].CustomName.Contains(sCameraViewOnly)) { continue; // don't add it to our list. } IMyCameraBlock camera = cameraAllList[i] as IMyCameraBlock; camera.EnableRaycast = true; Matrix fromcameraToGrid; camera.Orientation.GetMatrix(out fromcameraToGrid); Vector3 accelerationDirection = Vector3.Transform(fromcameraToGrid.Forward, fromGridToReference); if (accelerationDirection == cameraidentityMatrix.Left) { cameraLeftList.Add(cameraAllList[i]); } else if (accelerationDirection == cameraidentityMatrix.Right) { cameraRightList.Add(cameraAllList[i]); } else if (accelerationDirection == cameraidentityMatrix.Backward) { cameraBackwardList.Add(cameraAllList[i]); } else if (accelerationDirection == cameraidentityMatrix.Forward) { cameraForwardList.Add(cameraAllList[i]); } else if (accelerationDirection == cameraidentityMatrix.Up) { cameraUpList.Add(cameraAllList[i]); } else if (accelerationDirection == cameraidentityMatrix.Down) { cameraDownList.Add(cameraAllList[i]); } } string s; s = "CS:<"; s += "F" + cameraForwardList.Count.ToString("00"); s += "B" + cameraBackwardList.Count.ToString("00"); s += "D" + cameraDownList.Count.ToString("00"); s += "U" + cameraUpList.Count.ToString("00"); s += "L" + cameraLeftList.Count.ToString("00"); s += "R" + cameraRightList.Count.ToString("00"); s += ">"; return(s); }
public Sensor(IMyCameraBlock camera) { this.camera = camera; }
public EntityTrackingMotionController(MyDetectedEntityInfo entity, IMyCameraBlock camera) { this.entity = entity; this.camera = camera; }
public SurfaceScanner(IMyCameraBlock groundCam, IMyShipController rc) { this.rc = rc; this.groundCam = groundCam; groundCam.EnableRaycast = true; }
public TargetPainter(IMyCameraBlock targetingCamera, List <IMyCameraBlock> cameras) { this.targetingCamera = targetingCamera; this.cameras = cameras; }
public void Main(string argument, UpdateType updateSource) { // The main entry point of the script, invoked every time // one of the programmable block's Run actions are invoked, // or the script updates itself. The updateSource argument // describes where the update came from. // // The method itself is required, but the arguments above // can be removed if not needed. if (firstrun) { Echo("first run"); firstrun = false; List <IMyTerminalBlock> blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocks(blocks); foreach (var block in blocks) { if (block is IMyCameraBlock && block.CustomName == "Forward Camera") { camera = (IMyCameraBlock)block; } if (block is IMyTextPanel && block.CustomName == "Distance Display") { lcd = (IMyTextPanel)block; } if (block is IMyTextPanel && block.CustomName == "Range Display") { rangeDisp = (IMyTextPanel)block; } } camera.EnableRaycast = true; } if (argument == "Update" || argument == "") { range.Clear(); range.Append("Range: " + (camera.AvailableScanRange / 1000).ToString()); rangeDisp.WriteText(range.ToString()); lcd.WriteText(sb.ToString()); return; } count++; int value = 0; if (int.TryParse(argument, out value)) { if (value != 0) { SCAN_DISTANCE = value; } } if (camera.CanScan(SCAN_DISTANCE)) { info = camera.Raycast(SCAN_DISTANCE, PITCH, YAW); } sb.Clear(); sb.Append("EntityID: " + info.EntityId); sb.AppendLine(); sb.Append("Name: " + info.Name); sb.AppendLine(); sb.Append("Type: " + info.Type); sb.AppendLine(); sb.Append("Velocity: " + info.Velocity.ToString("0.000")); sb.AppendLine(); sb.Append("Relationship: " + info.Relationship); sb.AppendLine(); sb.Append("Size: " + info.BoundingBox.Size.ToString("0.000")); sb.AppendLine(); sb.Append("Position: " + info.Position.ToString("0.000")); if (info.HitPosition.HasValue) { sb.AppendLine(); sb.Append("Hit: " + info.HitPosition.Value.ToString("0.000")); sb.AppendLine(); sb.Append("Distance: " + Vector3D.Distance(camera.GetPosition(), info.HitPosition.Value).ToString("0.00")); } sb.AppendLine(); sb.Append("Range: " + camera.AvailableScanRange.ToString()); lcd.WriteText(sb.ToString()); }