Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Sandbox.Game.Entities;
- using Sandbox.Game.EntityComponents;
- using Sandbox.ModAPI;
- using Sandbox.ModAPI.Ingame;
- using Sandbox.ModAPI.Interfaces;
- using SpaceEngineers.Game.ModAPI;
- using VRage.Game;
- using VRage.Game.Components;
- using VRage.Game.ModAPI;
- using VRage.ModAPI;
- using VRage.Utils;
- using VRageMath;
- using Sandbox.ModAPI.Interfaces.Terminal;
- using ParallelTasks;
- using Sandbox.Common.ObjectBuilders;
- using VRage.ObjectBuilders;
- using IMyLargeTurretBase = Sandbox.ModAPI.IMyLargeTurretBase;
- namespace Zkillerproxy {
- [MyEntityComponentDescriptor(typeof(MyObjectBuilder_LargeGatlingTurret), true)]
- public class SmartTurret : MyGameLogicComponent {
- private static List<MyTerminalControlListBoxItem> _items;
- private IMyLargeTurretBase _turret;
- //Guids
- Guid myGUID1 = new Guid("b7f48e01-f86f-4cc3-9bdd-5d4c3b643afc");
- Guid myGUID2 = new Guid("1f69ad8a-626a-4035-a3de-f71b288b6a07");
- Guid myGUID3 = new Guid("93346b49-7abc-46df-9dff-c2ecc34ec62a");
- Guid myGUID4 = new Guid("1f5b1e05-9193-472f-98c5-383a5a22d6e3");
- Guid myGUID5 = new Guid("b3c0f5a3-6a73-4884-bb53-04c6c524595e");
- Guid myGUID6 = new Guid("d77ca9fe-580f-41b5-b8cf-09640874430f");
- Guid myGUID7 = new Guid("ddb1f892-4949-402a-bae4-2b8461893f1d");
- Guid myGUID8 = new Guid("1bf384cf-97e0-4c34-b4d2-8a513a8c84fd");
- Guid myGUID9 = new Guid("7cd5b7a4-baff-47b2-9660-6f42e75a84ea");
- Guid myGUID10 = new Guid("e5e62d16-d74c-45ab-8c4c-01805a295f4b");
- Guid myGUID11 = new Guid("b6b4b117-e661-407a-ba26-272dd25a2865");
- Guid myTargetStorageGUID = new Guid("6cddbff8-96a8-49c3-aaf0-b846d83acf1d");
- Guid turretIsResettingGUID = new Guid("0fb04606-2dd2-4733-9a3d-bd966300a397");
- Guid turretResettingClockGUID = new Guid("ae798b8b-2b57-4c86-890e-7739971bb19a");
- //Terminal control variables
- IMyTerminalControlOnOffSwitch smartTargetingSwitch;
- IMyTerminalControlOnOffSwitch trackTarget;
- IMyTerminalControlSlider smartTargetRange;
- IMyTerminalControlOnOffSwitch canFireThroughTargetGrid;
- IMyTerminalControlSlider manhattanToleranceSlider;
- IMyTerminalControlOnOffSwitch canFireThroughHostiles;
- IMyTerminalControlOnOffSwitch canFireThroughNeutrals;
- IMyTerminalControlOnOffSwitch canFireThroughFriendlies;
- IMyTerminalControlSlider minTargetSizeSlider;
- IMyTerminalControlButton targetTypesEnableDisable;
- IMyTerminalControlButton targetTypesPriorityUp;
- IMyTerminalControlButton targetTypesPriorityDown;
- IMyTerminalControlListbox targetTypesList;
- public override void Init(MyObjectBuilder_EntityBase objectBuilder) {
- _turret = Entity as IMyLargeTurretBase;
- CreateTerminalControls();
- NeedsUpdate = MyEntityUpdateEnum.EACH_10TH_FRAME;
- }
- public override void UpdateBeforeSimulation10() {
- // todo: do the targeting stuff
- }
- private void CreateTerminalControls() {
- if (_items == null) {
- //Set defult target list.
- _items = new List<MyTerminalControlListBoxItem> {
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(+) Turrets"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyLargeTurretBase'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(+) Fixed Weapons"), MyStringId.GetOrCompute("Target blocks that fall under 'IMySmallGatlingGun', 'IMySmallMissileLauncher' and 'IMySmallMissileLauncherReload'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(+) Warheads"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyWarhead'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(+) Control Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyRemoteControl' and 'IMyCockpit'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Sensors"), MyStringId.GetOrCompute("Target blocks that fall under 'IMySensorBlock'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Cameras"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyCameraBlock'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Power Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyReactor', 'IMyBatteryBlock' and 'IMySolarPanel'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Jump Drives"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyJumpDrive'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Projectors"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyProjector'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Ship Tools"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyShipToolBase' and 'IMyShipDrill'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Programmable Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyProgrammableBlock'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Timer Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyTimerBlock'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Thrusters"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyThrust'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Gyroscopes"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyGyro'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Communication Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyRadioAntenna', 'IMyLaserAntenna' and 'IMyBeacon'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Medical Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyCryoChamber' and 'IMyMedicalRoom'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Oxygen Generators"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyGasGenerator'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Gas Tanks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyGasTank'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Gravity Generators"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyGravityGeneratorBase'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Artificial Masses"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyArtificialMassBlock'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Parachute Hatches"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyParachute'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Landing Gears"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyLandingGear'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Ore Detectors"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyOreDetector'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Physics Blocks and Wheels"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyPistonBase' and 'IMyMotorBase'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Merge Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyShipMergeBlock'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Connectors"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyShipConnector'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Production Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyProductionBlock'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Doors"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyDoor'"), null),
- new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Cargo Containers"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyCargoContainer'"), null)
- };
- }
- //Divider
- var divider1 = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSeparator, Sandbox.ModAPI.IMyLargeTurretBase>("Divider1");
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(divider1);
- //SmartTargetingSwitch
- smartTargetingSwitch = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, Sandbox.ModAPI.IMyLargeTurretBase>("SmartTargetingSwitch");
- smartTargetingSwitch.Getter = smartTargetingSwitchGetter;
- smartTargetingSwitch.Setter = smartTargetingSwitchSetter;
- smartTargetingSwitch.Title = MyStringId.GetOrCompute("Use Smart Targeting");
- smartTargetingSwitch.Tooltip = MyStringId.GetOrCompute("Use Smart Targeting AI");
- smartTargetingSwitch.SupportsMultipleBlocks = true;
- smartTargetingSwitch.OffText = MyStringId.GetOrCompute("Off");
- smartTargetingSwitch.OnText = MyStringId.GetOrCompute("On");
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(smartTargetingSwitch);
- //SmartTargetingSwitch Action
- var actionSmartTargetingSwitch = MyAPIGateway.TerminalControls.CreateAction<Sandbox.ModAPI.IMyLargeTurretBase>("SmartTargetingSwitchAction");
- actionSmartTargetingSwitch.Action = smartTargetingSwitchAction;
- actionSmartTargetingSwitch.Name = new StringBuilder("Use Smart Targeting On/Off");
- actionSmartTargetingSwitch.Writer = SmartTargetingSwitchWriter;
- MyAPIGateway.TerminalControls.AddAction<Sandbox.ModAPI.IMyLargeTurretBase>(actionSmartTargetingSwitch);
- //Divider
- var divider2 = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSeparator, Sandbox.ModAPI.IMyLargeTurretBase>("Divider2");
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(divider2);
- //TrackTarget
- trackTarget = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, Sandbox.ModAPI.IMyLargeTurretBase>("TrackTarget");
- trackTarget.Getter = trackTargetSwitchGetter;
- trackTarget.Setter = trackTargetSwitchSetter;
- trackTarget.Title = MyStringId.GetOrCompute("Track Target");
- trackTarget.Tooltip = MyStringId.GetOrCompute("Determines if the turret should track targets");
- trackTarget.SupportsMultipleBlocks = true;
- trackTarget.OffText = MyStringId.GetOrCompute("Off");
- trackTarget.OnText = MyStringId.GetOrCompute("On");
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(trackTarget);
- //TrackTarget Action
- var actionTrackTarget = MyAPIGateway.TerminalControls.CreateAction<Sandbox.ModAPI.IMyLargeTurretBase>("TrackTargetAction");
- actionTrackTarget.Action = trackTargetSwitchAction;
- actionTrackTarget.Name = new StringBuilder("Track Target On/Off");
- actionTrackTarget.Writer = trackTargetSwitchWriter;
- MyAPIGateway.TerminalControls.AddAction<Sandbox.ModAPI.IMyLargeTurretBase>(actionTrackTarget);
- //SmartTargetRangeSlider
- smartTargetRange = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSlider, Sandbox.ModAPI.IMyLargeTurretBase>("SmartTargetRangeSlider");
- smartTargetRange.Getter = smartTargetRangeSliderGetter;
- smartTargetRange.Setter = smartTargetRangeSliderSetter;
- smartTargetRange.Title = MyStringId.GetOrCompute("Smart Target Range");
- smartTargetRange.SupportsMultipleBlocks = true;
- smartTargetRange.SetLimits(0, 800);
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(smartTargetRange);
- //CanFireThroughTargetGrid
- canFireThroughTargetGrid = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughTargetGrid");
- canFireThroughTargetGrid.Getter = canFireThroughTargetGridSwitchGetter;
- canFireThroughTargetGrid.Setter = canFireThroughTargetGridSwitchSetter;
- canFireThroughTargetGrid.Title = MyStringId.GetOrCompute("Fire Through The Target Grid");
- canFireThroughTargetGrid.Tooltip = MyStringId.GetOrCompute("Should the turret fire through other blocks on the target's grid to hit it's target");
- canFireThroughTargetGrid.SupportsMultipleBlocks = true;
- canFireThroughTargetGrid.OffText = MyStringId.GetOrCompute("False");
- canFireThroughTargetGrid.OnText = MyStringId.GetOrCompute("True");
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(canFireThroughTargetGrid);
- //CanFireThroughTargetGrid Action
- var actionCanFireThroughTargetGrid = MyAPIGateway.TerminalControls.CreateAction<Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughTargetGridAction");
- actionCanFireThroughTargetGrid.Action = canFireThroughTargetGridSwitchAction;
- actionCanFireThroughTargetGrid.Name = new StringBuilder("Fire Through The Target Grid On/Off");
- actionCanFireThroughTargetGrid.Writer = canFireThroughTargetGridSwitchWriter;
- MyAPIGateway.TerminalControls.AddAction<Sandbox.ModAPI.IMyLargeTurretBase>(actionCanFireThroughTargetGrid);
- //ManhattanToleranceSlider
- manhattanToleranceSlider = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSlider, Sandbox.ModAPI.IMyLargeTurretBase>("ManhattanToleranceSlider");
- manhattanToleranceSlider.Getter = manhattanToleranceSliderGetter;
- manhattanToleranceSlider.Setter = manhattanToleranceSliderSetter;
- manhattanToleranceSlider.Title = MyStringId.GetOrCompute("Obstacle Block Tolerance");
- manhattanToleranceSlider.Tooltip = MyStringId.GetOrCompute("When not firing through the target grid, this slider determines the number of blocks on the target block's grid the turret will shoot through to reach the target");
- manhattanToleranceSlider.SupportsMultipleBlocks = true;
- manhattanToleranceSlider.SetLimits(0, 10);
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(manhattanToleranceSlider);
- //CanFireThroughHostiles
- canFireThroughHostiles = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughHostiles");
- canFireThroughHostiles.Getter = canFireThroughHostilesSwitchGetter;
- canFireThroughHostiles.Setter = canFireThroughHostilesSwitchSetter;
- canFireThroughHostiles.Title = MyStringId.GetOrCompute("Fire Through Hostile Grids");
- canFireThroughHostiles.Tooltip = MyStringId.GetOrCompute("Should the turret fire through other hostile grids to hit it's target");
- canFireThroughHostiles.SupportsMultipleBlocks = true;
- canFireThroughHostiles.OffText = MyStringId.GetOrCompute("False");
- canFireThroughHostiles.OnText = MyStringId.GetOrCompute("True");
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(canFireThroughHostiles);
- //CanFireThroughHostiles Action
- var actionCanFireThroughHostiles = MyAPIGateway.TerminalControls.CreateAction<Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughHostilesAction");
- actionCanFireThroughHostiles.Action = canFireThroughHostilesSwitchAction;
- actionCanFireThroughHostiles.Name = new StringBuilder("Fire Through Hostile Grids On/Off");
- actionCanFireThroughHostiles.Writer = canFireThroughHostilesSwitchWriter;
- MyAPIGateway.TerminalControls.AddAction<Sandbox.ModAPI.IMyLargeTurretBase>(actionCanFireThroughHostiles);
- //CanFireThroughNeutrals
- canFireThroughNeutrals = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughNeutrals");
- canFireThroughNeutrals.Getter = canFireThroughNeutralsSwitchGetter;
- canFireThroughNeutrals.Setter = canFireThroughNeutralsSwitchSetter;
- canFireThroughNeutrals.Title = MyStringId.GetOrCompute("Fire Through Neutrals Grids");
- canFireThroughNeutrals.Tooltip = MyStringId.GetOrCompute("Should the turret fire through neutral grids to hit it's target");
- canFireThroughNeutrals.SupportsMultipleBlocks = true;
- canFireThroughNeutrals.OffText = MyStringId.GetOrCompute("False");
- canFireThroughNeutrals.OnText = MyStringId.GetOrCompute("True");
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(canFireThroughNeutrals);
- //CanFireThroughNeutrals Action
- var actionCanFireThroughNeutrals = MyAPIGateway.TerminalControls.CreateAction<Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughNeutralsAction");
- actionCanFireThroughNeutrals.Action = canFireThroughNeutralsSwitchAction;
- actionCanFireThroughNeutrals.Name = new StringBuilder("Fire Through Neutral Grids On/Off");
- actionCanFireThroughNeutrals.Writer = canFireThroughNeutralsSwitchWriter;
- MyAPIGateway.TerminalControls.AddAction<Sandbox.ModAPI.IMyLargeTurretBase>(actionCanFireThroughNeutrals);
- //CanFireThroughFriendlies
- canFireThroughFriendlies = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughFriendlies");
- canFireThroughFriendlies.Getter = canFireThroughFriendliesSwitchGetter;
- canFireThroughFriendlies.Setter = canFireThroughFriendliesSwitchSetter;
- canFireThroughFriendlies.Title = MyStringId.GetOrCompute("Fire Through Friendly Grids");
- canFireThroughFriendlies.SupportsMultipleBlocks = true;
- canFireThroughFriendlies.Tooltip = MyStringId.GetOrCompute("Should the turret fire through friendly grids to hit it's target. WARNING: MAY INCLUDE TURRET'S GRID!");
- canFireThroughFriendlies.OffText = MyStringId.GetOrCompute("False");
- canFireThroughFriendlies.OnText = MyStringId.GetOrCompute("True");
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(canFireThroughFriendlies);
- //CanFireThroughFriendlies Action
- var actionCanFireThroughFriendlies = MyAPIGateway.TerminalControls.CreateAction<Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughFriendliesAction");
- actionCanFireThroughFriendlies.Action = canFireThroughFriendliesSwitchAction;
- actionCanFireThroughFriendlies.Name = new StringBuilder("Fire Through Friendly Grids On/Off");
- actionCanFireThroughFriendlies.Writer = canFireThroughFriendliesSwitchWriter;
- MyAPIGateway.TerminalControls.AddAction<Sandbox.ModAPI.IMyLargeTurretBase>(actionCanFireThroughFriendlies);
- //MinTargetSizeSlider
- minTargetSizeSlider = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSlider, Sandbox.ModAPI.IMyLargeTurretBase>("MinTargetSizeSlider");
- minTargetSizeSlider.Getter = minTargetSizeSliderGetter;
- minTargetSizeSlider.Setter = minTargetSizeSliderSetter;
- minTargetSizeSlider.Title = MyStringId.GetOrCompute("Minimum Target Grid Size");
- minTargetSizeSlider.Tooltip = MyStringId.GetOrCompute("Only blocks on grids equal to or greater than this value will be targeted");
- minTargetSizeSlider.SupportsMultipleBlocks = true;
- minTargetSizeSlider.SetLimits(0, 300);
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(minTargetSizeSlider);
- //Divider
- var divider3 = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSeparator, Sandbox.ModAPI.IMyLargeTurretBase>("Divider3");
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(divider3);
- //Title
- var titleTypes = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlLabel, Sandbox.ModAPI.IMyLargeTurretBase>("TitleTypes");
- titleTypes.Label = MyStringId.GetOrCompute("Targeting Priorities");
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(titleTypes);
- //TargetTypesEnableDisable
- targetTypesEnableDisable = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlButton, Sandbox.ModAPI.IMyLargeTurretBase>("TargetTypesEnableDisable");
- targetTypesEnableDisable.Action = targetTypesEnableDisableAction;
- targetTypesEnableDisable.SupportsMultipleBlocks = false;
- targetTypesEnableDisable.Title = MyStringId.GetOrCompute("Enable/Disable");
- targetTypesEnableDisable.Tooltip = MyStringId.GetOrCompute("(+) == Enabled, (-) == Disabled");
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(targetTypesEnableDisable);
- //TargetTypesPriorityUp
- targetTypesPriorityUp = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlButton, Sandbox.ModAPI.IMyLargeTurretBase>("TargetTypesPriorityUp");
- targetTypesPriorityUp.Action = targetTypesPriorityUpAction;
- targetTypesPriorityUp.SupportsMultipleBlocks = false;
- targetTypesPriorityUp.Title = MyStringId.GetOrCompute("Priority Up");
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(targetTypesPriorityUp);
- //TargetTypesPriorityDown
- targetTypesPriorityDown = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlButton, Sandbox.ModAPI.IMyLargeTurretBase>("TargetTypesPriorityDown");
- targetTypesPriorityDown.Action = targetTypesPriorityDownAction;
- targetTypesPriorityDown.SupportsMultipleBlocks = false;
- targetTypesPriorityDown.Title = MyStringId.GetOrCompute("Priority Down");
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(targetTypesPriorityDown);
- //TargetTypesList
- targetTypesList = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlListbox, Sandbox.ModAPI.IMyLargeTurretBase>("TargetTypesList");
- targetTypesList.ListContent = targetTypesListPopulator;
- targetTypesList.ItemSelected = targetTypesListSelector;
- targetTypesList.SupportsMultipleBlocks = false;
- targetTypesList.Multiselect = false;
- targetTypesList.VisibleRowsCount = 29;
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(targetTypesList);
- //Divider
- var divider4 = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSeparator, Sandbox.ModAPI.IMyLargeTurretBase>("Divider4");
- MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(divider4);
- }
- //SmartTargetingSwitch Setter/Getter/Action
- bool smartTargetingSwitchGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- thisBlock.Storage[myGUID1] = "false";
- return false;
- } else if (thisBlock.Storage.TryGetValue(myGUID1, out Nulled) == false) {
- thisBlock.Storage[myGUID1] = "false";
- return false;
- } else {
- return bool.Parse(thisBlock.Storage[myGUID1]);
- }
- }
- void smartTargetingSwitchSetter(Sandbox.ModAPI.IMyTerminalBlock turret, bool newValue) {
- IMyEntity thisBlock = turret as IMyEntity;
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- }
- thisBlock.Storage[myGUID1] = newValue.ToString();
- turret.ApplyAction("Shoot_Off");
- if (newValue) {
- if (turret.HasAction("TargetMeteors_Off")) {
- turret.ApplyAction("TargetMeteors_Off");
- }
- if (turret.HasAction("TargetMissiles_Off")) {
- turret.ApplyAction("TargetMissiles_Off");
- }
- if (turret.HasAction("TargetSmallShips_Off")) {
- turret.ApplyAction("TargetSmallShips_Off");
- }
- if (turret.HasAction("TargetLargeShips_Off")) {
- turret.ApplyAction("TargetLargeShips_Off");
- }
- if (turret.HasAction("TargetCharacters_Off")) {
- turret.ApplyAction("TargetCharacters_Off");
- }
- if (turret.HasAction("TargetStations_Off")) {
- turret.ApplyAction("TargetStations_Off");
- }
- }
- }
- void smartTargetingSwitchAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- smartTargetingSwitchSetter(turret, true);
- } else if (thisBlock.Storage.TryGetValue(myGUID1, out Nulled) == false) {
- smartTargetingSwitchSetter(turret, true);
- } else {
- smartTargetingSwitchSetter(turret, !bool.Parse(thisBlock.Storage[myGUID1]));
- }
- }
- void SmartTargetingSwitchWriter(Sandbox.ModAPI.IMyTerminalBlock turret, StringBuilder text) {
- text.Clear();
- if (smartTargetingSwitchGetter(turret)) {
- text.Append("On");
- } else {
- text.Append("Off");
- }
- }
- //------------------------------------------------------------------------------
- //trackTargetSwitch Setter/Getter
- bool trackTargetSwitchGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- thisBlock.Storage[myGUID9] = "true";
- return true;
- } else if (thisBlock.Storage.TryGetValue(myGUID9, out Nulled) == false) {
- thisBlock.Storage[myGUID9] = "true";
- return true;
- } else {
- return bool.Parse(thisBlock.Storage[myGUID9]);
- }
- }
- void trackTargetSwitchSetter(Sandbox.ModAPI.IMyTerminalBlock turret, bool newValue) {
- IMyEntity thisBlock = turret as IMyEntity;
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- }
- thisBlock.Storage[myGUID9] = newValue.ToString();
- }
- void trackTargetSwitchAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- trackTargetSwitchSetter(turret, true);
- } else if (thisBlock.Storage.TryGetValue(myGUID9, out Nulled) == false) {
- trackTargetSwitchSetter(turret, true);
- } else {
- trackTargetSwitchSetter(turret, !bool.Parse(thisBlock.Storage[myGUID9]));
- }
- }
- void trackTargetSwitchWriter(Sandbox.ModAPI.IMyTerminalBlock turret, StringBuilder text) {
- text.Clear();
- if (trackTargetSwitchGetter(turret)) {
- text.Append("On");
- } else {
- text.Append("Off");
- }
- }
- //------------------------------------------------------------------------------
- //ManhattanToleranceSlider Setter/Getter
- float smartTargetRangeSliderGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- thisBlock.Storage[myGUID11] = "800";
- return 800;
- } else if (thisBlock.Storage.TryGetValue(myGUID11, out Nulled) == false) {
- thisBlock.Storage[myGUID11] = "800";
- return 800;
- } else {
- return float.Parse(thisBlock.Storage[myGUID11]);
- }
- }
- void smartTargetRangeSliderSetter(Sandbox.ModAPI.IMyTerminalBlock turret, float newValue) {
- IMyEntity thisBlock = turret as IMyEntity;
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- }
- thisBlock.Storage[myGUID11] = newValue.ToString();
- smartTargetRange.UpdateVisual();
- }
- //------------------------------------------------------------------------------
- //CanFireThroughTargetGrid Setter/Getter
- bool canFireThroughTargetGridSwitchGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- thisBlock.Storage[myGUID6] = "false";
- return false;
- } else if (thisBlock.Storage.TryGetValue(myGUID6, out Nulled) == false) {
- thisBlock.Storage[myGUID6] = "false";
- return false;
- } else {
- return bool.Parse(thisBlock.Storage[myGUID6]);
- }
- }
- void canFireThroughTargetGridSwitchSetter(Sandbox.ModAPI.IMyTerminalBlock turret, bool newValue) {
- IMyEntity thisBlock = turret as IMyEntity;
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- }
- thisBlock.Storage[myGUID6] = newValue.ToString();
- if (newValue == true) {
- manhattanToleranceSlider.Enabled = (block) => false;
- manhattanToleranceSlider.UpdateVisual();
- } else {
- manhattanToleranceSlider.Enabled = (block) => true;
- manhattanToleranceSlider.UpdateVisual();
- }
- }
- void canFireThroughTargetGridSwitchAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- canFireThroughTargetGridSwitchSetter(turret, true);
- } else if (thisBlock.Storage.TryGetValue(myGUID6, out Nulled) == false) {
- canFireThroughTargetGridSwitchSetter(turret, true);
- } else {
- canFireThroughTargetGridSwitchSetter(turret, !bool.Parse(thisBlock.Storage[myGUID6]));
- }
- }
- void canFireThroughTargetGridSwitchWriter(Sandbox.ModAPI.IMyTerminalBlock turret, StringBuilder text) {
- text.Clear();
- if (canFireThroughTargetGridSwitchGetter(turret)) {
- text.Append("On");
- } else {
- text.Append("Off");
- }
- }
- //------------------------------------------------------------------------------
- //ManhattanToleranceSlider Setter/Getter
- float manhattanToleranceSliderGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage.TryGetValue(myGUID6, out Nulled) == true) {
- if (bool.Parse(thisBlock.Storage[myGUID6])) {
- manhattanToleranceSlider.Enabled = (block) => false;
- } else {
- manhattanToleranceSlider.Enabled = (block) => true;
- }
- }
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- thisBlock.Storage[myGUID10] = "3";
- return 3;
- } else if (thisBlock.Storage.TryGetValue(myGUID10, out Nulled) == false) {
- thisBlock.Storage[myGUID10] = "3";
- return 3;
- } else {
- return float.Parse(thisBlock.Storage[myGUID10]);
- }
- }
- void manhattanToleranceSliderSetter(Sandbox.ModAPI.IMyTerminalBlock turret, float newValue) {
- IMyEntity thisBlock = turret as IMyEntity;
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- }
- thisBlock.Storage[myGUID10] = Math.Floor(newValue).ToString();
- manhattanToleranceSlider.UpdateVisual();
- }
- //------------------------------------------------------------------------------
- //CanFireThroughHostiles Setter/Getter
- bool canFireThroughHostilesSwitchGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- thisBlock.Storage[myGUID3] = "false";
- return false;
- } else if (thisBlock.Storage.TryGetValue(myGUID3, out Nulled) == false) {
- thisBlock.Storage[myGUID3] = "false";
- return false;
- } else {
- return bool.Parse(thisBlock.Storage[myGUID3]);
- }
- }
- void canFireThroughHostilesSwitchSetter(Sandbox.ModAPI.IMyTerminalBlock turret, bool newValue) {
- IMyEntity thisBlock = turret as IMyEntity;
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- }
- thisBlock.Storage[myGUID3] = newValue.ToString();
- }
- void canFireThroughHostilesSwitchAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- canFireThroughHostilesSwitchSetter(turret, true);
- } else if (thisBlock.Storage.TryGetValue(myGUID3, out Nulled) == false) {
- canFireThroughHostilesSwitchSetter(turret, true);
- } else {
- canFireThroughHostilesSwitchSetter(turret, !bool.Parse(thisBlock.Storage[myGUID3]));
- }
- }
- void canFireThroughHostilesSwitchWriter(Sandbox.ModAPI.IMyTerminalBlock turret, StringBuilder text) {
- text.Clear();
- if (canFireThroughHostilesSwitchGetter(turret)) {
- text.Append("On");
- } else {
- text.Append("Off");
- }
- }
- //------------------------------------------------------------------------------
- //CanFireThroughNeutrals Setter/Getter
- bool canFireThroughNeutralsSwitchGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- thisBlock.Storage[myGUID4] = "false";
- return false;
- } else if (thisBlock.Storage.TryGetValue(myGUID4, out Nulled) == false) {
- thisBlock.Storage[myGUID4] = "false";
- return false;
- } else {
- return bool.Parse(thisBlock.Storage[myGUID4]);
- }
- }
- void canFireThroughNeutralsSwitchSetter(Sandbox.ModAPI.IMyTerminalBlock turret, bool newValue) {
- IMyEntity thisBlock = turret as IMyEntity;
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- }
- thisBlock.Storage[myGUID4] = newValue.ToString();
- }
- void canFireThroughNeutralsSwitchAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- canFireThroughNeutralsSwitchSetter(turret, true);
- } else if (thisBlock.Storage.TryGetValue(myGUID4, out Nulled) == false) {
- canFireThroughNeutralsSwitchSetter(turret, true);
- } else {
- canFireThroughNeutralsSwitchSetter(turret, !bool.Parse(thisBlock.Storage[myGUID4]));
- }
- }
- void canFireThroughNeutralsSwitchWriter(Sandbox.ModAPI.IMyTerminalBlock turret, StringBuilder text) {
- text.Clear();
- if (canFireThroughNeutralsSwitchGetter(turret)) {
- text.Append("On");
- } else {
- text.Append("Off");
- }
- }
- //------------------------------------------------------------------------------
- //CanFireThroughFriendlies Setter/Getter
- bool canFireThroughFriendliesSwitchGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- thisBlock.Storage[myGUID5] = "false";
- return false;
- } else if (thisBlock.Storage.TryGetValue(myGUID5, out Nulled) == false) {
- thisBlock.Storage[myGUID5] = "false";
- return false;
- } else {
- return bool.Parse(thisBlock.Storage[myGUID5]);
- }
- }
- void canFireThroughFriendliesSwitchSetter(Sandbox.ModAPI.IMyTerminalBlock turret, bool newValue) {
- IMyEntity thisBlock = turret as IMyEntity;
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- }
- thisBlock.Storage[myGUID5] = newValue.ToString();
- }
- void canFireThroughFriendliesSwitchAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- canFireThroughFriendliesSwitchSetter(turret, true);
- } else if (thisBlock.Storage.TryGetValue(myGUID5, out Nulled) == false) {
- canFireThroughFriendliesSwitchSetter(turret, true);
- } else {
- canFireThroughFriendliesSwitchSetter(turret, !bool.Parse(thisBlock.Storage[myGUID5]));
- }
- }
- void canFireThroughFriendliesSwitchWriter(Sandbox.ModAPI.IMyTerminalBlock turret, StringBuilder text) {
- text.Clear();
- if (canFireThroughFriendliesSwitchGetter(turret)) {
- text.Append("On");
- } else {
- text.Append("Off");
- }
- }
- //------------------------------------------------------------------------------
- //MinTargetSizeSlider Setter/Getter
- float minTargetSizeSliderGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- thisBlock.Storage[myGUID2] = "0";
- return 0;
- } else if (thisBlock.Storage.TryGetValue(myGUID2, out Nulled) == false) {
- thisBlock.Storage[myGUID2] = "0";
- return 0;
- } else {
- return float.Parse(thisBlock.Storage[myGUID2]);
- }
- }
- void minTargetSizeSliderSetter(Sandbox.ModAPI.IMyTerminalBlock turret, float newValue) {
- IMyEntity thisBlock = turret as IMyEntity;
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- }
- thisBlock.Storage[myGUID2] = Math.Floor(newValue).ToString();
- minTargetSizeSlider.UpdateVisual();
- }
- //------------------------------------------------------------------------------
- //TargetTypesEnableDisable Action
- void targetTypesEnableDisableAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- string storage = "";
- string[] storage1 = thisBlock.Storage[myGUID7].Split('/');
- string storage2 = thisBlock.Storage[myGUID8];
- List<MyTerminalControlListBoxItem> itemList = new List<MyTerminalControlListBoxItem>();
- for (var i = 0; i < storage1.Length; i++) {
- if (i % 2 != 0) {
- itemList.Add(new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(storage1[i - 1]), MyStringId.GetOrCompute(storage1[i]), null));
- }
- }
- foreach (var item1 in itemList) {
- if (item1.Text.String == storage2) {
- if (item1.Text.String.Contains("+")) {
- item1.Text = MyStringId.GetOrCompute(item1.Text.String.Replace('+', '-'));
- thisBlock.Storage[myGUID8] = item1.Text.String;
- } else {
- item1.Text = MyStringId.GetOrCompute(item1.Text.String.Replace('-', '+'));
- thisBlock.Storage[myGUID8] = item1.Text.String;
- }
- break;
- }
- }
- foreach (var item2 in itemList) {
- storage += item2.Text + "/" + item2.Tooltip + "/";
- }
- thisBlock.Storage[myGUID7] = storage.Remove(storage.Length - 1);
- targetTypesList.UpdateVisual();
- }
- //------------------------------------------------------------------------------
- //targetTypesPriorityUp Action
- void targetTypesPriorityUpAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- string[] storage1 = thisBlock.Storage[myGUID7].Split('/');
- string storage2 = thisBlock.Storage[myGUID8].Substring(4);
- string temp1 = "";
- string temp2 = "";
- for (int i = 0; i < storage1.Length; i++) {
- if (storage1[i].Substring(4) == storage2 && i > 1) {
- temp1 = storage1[i - 2];
- temp2 = storage1[i - 1];
- storage1[i - 2] = storage1[i];
- storage1[i - 1] = storage1[i + 1];
- storage1[i] = temp1;
- storage1[i + 1] = temp2;
- break;
- }
- }
- thisBlock.Storage[myGUID7] = string.Join("/", storage1);
- targetTypesList.UpdateVisual();
- }
- //------------------------------------------------------------------------------
- //targetTypesPriorityDown Action
- void targetTypesPriorityDownAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
- IMyEntity thisBlock = turret as IMyEntity;
- string[] storage1 = thisBlock.Storage[myGUID7].Split('/');
- string storage2 = thisBlock.Storage[myGUID8].Substring(4);
- string temp1 = "";
- string temp2 = "";
- for (int i = 0; i < storage1.Length; i++) {
- if (storage1[i].Substring(4) == storage2 && i < storage1.Length - 3) {
- temp1 = storage1[i + 2];
- temp2 = storage1[i + 3];
- storage1[i + 2] = storage1[i];
- storage1[i + 3] = storage1[i + 1];
- storage1[i] = temp1;
- storage1[i + 1] = temp2;
- break;
- }
- }
- thisBlock.Storage[myGUID7] = string.Join("/", storage1);
- targetTypesList.UpdateVisual();
- }
- //------------------------------------------------------------------------------
- //TargetTypesList Populator/Selector
- void targetTypesListPopulator(Sandbox.ModAPI.IMyTerminalBlock turret, List<MyTerminalControlListBoxItem> itemList, List<MyTerminalControlListBoxItem> selectedItemList) {
- IMyEntity thisBlock = turret as IMyEntity;
- var Nulled = "";
- if (thisBlock.Storage == null) {
- thisBlock.Storage = new MyModStorageComponent();
- string storage = "";
- foreach (var item in _items) {
- storage += item.Text + "/" + item.Tooltip + "/";
- itemList.Add(item);
- }
- thisBlock.Storage[myGUID7] = storage.Remove(storage.Length - 1);
- thisBlock.Storage[myGUID8] = "";
- return;
- } else if (thisBlock.Storage.TryGetValue(myGUID7, out Nulled) == false) {
- string storage = "";
- foreach (var item in _items) {
- storage += item.Text + "/" + item.Tooltip + "/";
- itemList.Add(item);
- }
- thisBlock.Storage[myGUID7] = storage.Remove(storage.Length - 1);
- thisBlock.Storage[myGUID8] = "";
- return;
- } else {
- string[] storage1 = thisBlock.Storage[myGUID7].Split('/');
- for (var i = 0; i < storage1.Length; i++) {
- if (i % 2 != 0) {
- itemList.Add(new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(storage1[i - 1]), MyStringId.GetOrCompute(storage1[i]), null));
- }
- }
- selectedItemList.Clear();
- foreach (var item in itemList) {
- if (item.Text.String == thisBlock.Storage[myGUID8]) {
- selectedItemList.Add(item);
- }
- }
- return;
- }
- }
- void targetTypesListSelector(Sandbox.ModAPI.IMyTerminalBlock turret, List<MyTerminalControlListBoxItem> selectedItemList) {
- IMyEntity thisBlock = turret as IMyEntity;
- if (selectedItemList.Count != 0) {
- thisBlock.Storage[myGUID8] = selectedItemList[0].Text.String;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment