Guest User

Smart Turret MyGameLogicComponent Example

a guest
Dec 20th, 2017
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 47.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Sandbox.Game.Entities;
  6. using Sandbox.Game.EntityComponents;
  7. using Sandbox.ModAPI;
  8. using Sandbox.ModAPI.Ingame;
  9. using Sandbox.ModAPI.Interfaces;
  10. using SpaceEngineers.Game.ModAPI;
  11. using VRage.Game;
  12. using VRage.Game.Components;
  13. using VRage.Game.ModAPI;
  14. using VRage.ModAPI;
  15. using VRage.Utils;
  16. using VRageMath;
  17. using Sandbox.ModAPI.Interfaces.Terminal;
  18. using ParallelTasks;
  19. using Sandbox.Common.ObjectBuilders;
  20. using VRage.ObjectBuilders;
  21. using IMyLargeTurretBase = Sandbox.ModAPI.IMyLargeTurretBase;
  22.  
  23. namespace Zkillerproxy {
  24.     [MyEntityComponentDescriptor(typeof(MyObjectBuilder_LargeGatlingTurret), true)]
  25.     public class SmartTurret : MyGameLogicComponent {
  26.         private static List<MyTerminalControlListBoxItem> _items;
  27.         private IMyLargeTurretBase _turret;
  28.  
  29.         //Guids
  30.         Guid myGUID1 = new Guid("b7f48e01-f86f-4cc3-9bdd-5d4c3b643afc");
  31.         Guid myGUID2 = new Guid("1f69ad8a-626a-4035-a3de-f71b288b6a07");
  32.         Guid myGUID3 = new Guid("93346b49-7abc-46df-9dff-c2ecc34ec62a");
  33.         Guid myGUID4 = new Guid("1f5b1e05-9193-472f-98c5-383a5a22d6e3");
  34.         Guid myGUID5 = new Guid("b3c0f5a3-6a73-4884-bb53-04c6c524595e");
  35.         Guid myGUID6 = new Guid("d77ca9fe-580f-41b5-b8cf-09640874430f");
  36.         Guid myGUID7 = new Guid("ddb1f892-4949-402a-bae4-2b8461893f1d");
  37.         Guid myGUID8 = new Guid("1bf384cf-97e0-4c34-b4d2-8a513a8c84fd");
  38.         Guid myGUID9 = new Guid("7cd5b7a4-baff-47b2-9660-6f42e75a84ea");
  39.         Guid myGUID10 = new Guid("e5e62d16-d74c-45ab-8c4c-01805a295f4b");
  40.         Guid myGUID11 = new Guid("b6b4b117-e661-407a-ba26-272dd25a2865");
  41.         Guid myTargetStorageGUID = new Guid("6cddbff8-96a8-49c3-aaf0-b846d83acf1d");
  42.         Guid turretIsResettingGUID = new Guid("0fb04606-2dd2-4733-9a3d-bd966300a397");
  43.         Guid turretResettingClockGUID = new Guid("ae798b8b-2b57-4c86-890e-7739971bb19a");
  44.  
  45.         //Terminal control variables
  46.         IMyTerminalControlOnOffSwitch smartTargetingSwitch;
  47.         IMyTerminalControlOnOffSwitch trackTarget;
  48.         IMyTerminalControlSlider smartTargetRange;
  49.         IMyTerminalControlOnOffSwitch canFireThroughTargetGrid;
  50.         IMyTerminalControlSlider manhattanToleranceSlider;
  51.         IMyTerminalControlOnOffSwitch canFireThroughHostiles;
  52.         IMyTerminalControlOnOffSwitch canFireThroughNeutrals;
  53.         IMyTerminalControlOnOffSwitch canFireThroughFriendlies;
  54.         IMyTerminalControlSlider minTargetSizeSlider;
  55.         IMyTerminalControlButton targetTypesEnableDisable;
  56.         IMyTerminalControlButton targetTypesPriorityUp;
  57.         IMyTerminalControlButton targetTypesPriorityDown;
  58.         IMyTerminalControlListbox targetTypesList;
  59.  
  60.  
  61.         public override void Init(MyObjectBuilder_EntityBase objectBuilder) {
  62.             _turret = Entity as IMyLargeTurretBase;
  63.  
  64.             CreateTerminalControls();
  65.             NeedsUpdate = MyEntityUpdateEnum.EACH_10TH_FRAME;
  66.         }
  67.  
  68.         public override void UpdateBeforeSimulation10() {
  69.             // todo: do the targeting stuff
  70.         }
  71.  
  72.         private void CreateTerminalControls() {
  73.             if (_items == null) {
  74.                 //Set defult target list.
  75.                 _items = new List<MyTerminalControlListBoxItem> {
  76.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(+) Turrets"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyLargeTurretBase'"), null),
  77.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(+) Fixed Weapons"), MyStringId.GetOrCompute("Target blocks that fall under 'IMySmallGatlingGun', 'IMySmallMissileLauncher' and 'IMySmallMissileLauncherReload'"), null),
  78.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(+) Warheads"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyWarhead'"), null),
  79.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(+) Control Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyRemoteControl' and 'IMyCockpit'"), null),
  80.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Sensors"), MyStringId.GetOrCompute("Target blocks that fall under 'IMySensorBlock'"), null),
  81.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Cameras"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyCameraBlock'"), null),
  82.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Power Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyReactor', 'IMyBatteryBlock' and 'IMySolarPanel'"), null),
  83.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Jump Drives"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyJumpDrive'"), null),
  84.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Projectors"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyProjector'"), null),
  85.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Ship Tools"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyShipToolBase' and 'IMyShipDrill'"), null),
  86.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Programmable Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyProgrammableBlock'"), null),
  87.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Timer Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyTimerBlock'"), null),
  88.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Thrusters"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyThrust'"), null),
  89.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Gyroscopes"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyGyro'"), null),
  90.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Communication Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyRadioAntenna', 'IMyLaserAntenna' and 'IMyBeacon'"), null),
  91.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Medical Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyCryoChamber' and 'IMyMedicalRoom'"), null),
  92.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Oxygen Generators"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyGasGenerator'"), null),
  93.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Gas Tanks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyGasTank'"), null),
  94.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Gravity Generators"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyGravityGeneratorBase'"), null),
  95.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Artificial Masses"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyArtificialMassBlock'"), null),
  96.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Parachute Hatches"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyParachute'"), null),
  97.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Landing Gears"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyLandingGear'"), null),
  98.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Ore Detectors"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyOreDetector'"), null),
  99.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Physics Blocks and Wheels"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyPistonBase' and 'IMyMotorBase'"), null),
  100.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Merge Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyShipMergeBlock'"), null),
  101.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Connectors"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyShipConnector'"), null),
  102.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Production Blocks"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyProductionBlock'"), null),
  103.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Doors"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyDoor'"), null),
  104.                     new MyTerminalControlListBoxItem(MyStringId.GetOrCompute("(-) Cargo Containers"), MyStringId.GetOrCompute("Target blocks that fall under 'IMyCargoContainer'"), null)
  105.                 };
  106.             }
  107.  
  108.             //Divider
  109.             var divider1 = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSeparator, Sandbox.ModAPI.IMyLargeTurretBase>("Divider1");
  110.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(divider1);
  111.  
  112.             //SmartTargetingSwitch
  113.             smartTargetingSwitch = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, Sandbox.ModAPI.IMyLargeTurretBase>("SmartTargetingSwitch");
  114.             smartTargetingSwitch.Getter = smartTargetingSwitchGetter;
  115.             smartTargetingSwitch.Setter = smartTargetingSwitchSetter;
  116.             smartTargetingSwitch.Title = MyStringId.GetOrCompute("Use Smart Targeting");
  117.             smartTargetingSwitch.Tooltip = MyStringId.GetOrCompute("Use Smart Targeting AI");
  118.             smartTargetingSwitch.SupportsMultipleBlocks = true;
  119.             smartTargetingSwitch.OffText = MyStringId.GetOrCompute("Off");
  120.             smartTargetingSwitch.OnText = MyStringId.GetOrCompute("On");
  121.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(smartTargetingSwitch);
  122.  
  123.             //SmartTargetingSwitch Action
  124.             var actionSmartTargetingSwitch = MyAPIGateway.TerminalControls.CreateAction<Sandbox.ModAPI.IMyLargeTurretBase>("SmartTargetingSwitchAction");
  125.             actionSmartTargetingSwitch.Action = smartTargetingSwitchAction;
  126.             actionSmartTargetingSwitch.Name = new StringBuilder("Use Smart Targeting On/Off");
  127.             actionSmartTargetingSwitch.Writer = SmartTargetingSwitchWriter;
  128.             MyAPIGateway.TerminalControls.AddAction<Sandbox.ModAPI.IMyLargeTurretBase>(actionSmartTargetingSwitch);
  129.  
  130.             //Divider
  131.             var divider2 = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSeparator, Sandbox.ModAPI.IMyLargeTurretBase>("Divider2");
  132.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(divider2);
  133.  
  134.             //TrackTarget
  135.             trackTarget = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, Sandbox.ModAPI.IMyLargeTurretBase>("TrackTarget");
  136.             trackTarget.Getter = trackTargetSwitchGetter;
  137.             trackTarget.Setter = trackTargetSwitchSetter;
  138.             trackTarget.Title = MyStringId.GetOrCompute("Track Target");
  139.             trackTarget.Tooltip = MyStringId.GetOrCompute("Determines if the turret should track targets");
  140.             trackTarget.SupportsMultipleBlocks = true;
  141.             trackTarget.OffText = MyStringId.GetOrCompute("Off");
  142.             trackTarget.OnText = MyStringId.GetOrCompute("On");
  143.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(trackTarget);
  144.  
  145.             //TrackTarget Action
  146.             var actionTrackTarget = MyAPIGateway.TerminalControls.CreateAction<Sandbox.ModAPI.IMyLargeTurretBase>("TrackTargetAction");
  147.             actionTrackTarget.Action = trackTargetSwitchAction;
  148.             actionTrackTarget.Name = new StringBuilder("Track Target On/Off");
  149.             actionTrackTarget.Writer = trackTargetSwitchWriter;
  150.             MyAPIGateway.TerminalControls.AddAction<Sandbox.ModAPI.IMyLargeTurretBase>(actionTrackTarget);
  151.  
  152.             //SmartTargetRangeSlider
  153.             smartTargetRange = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSlider, Sandbox.ModAPI.IMyLargeTurretBase>("SmartTargetRangeSlider");
  154.             smartTargetRange.Getter = smartTargetRangeSliderGetter;
  155.             smartTargetRange.Setter = smartTargetRangeSliderSetter;
  156.             smartTargetRange.Title = MyStringId.GetOrCompute("Smart Target Range");
  157.             smartTargetRange.SupportsMultipleBlocks = true;
  158.             smartTargetRange.SetLimits(0, 800);
  159.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(smartTargetRange);
  160.  
  161.             //CanFireThroughTargetGrid
  162.             canFireThroughTargetGrid = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughTargetGrid");
  163.             canFireThroughTargetGrid.Getter = canFireThroughTargetGridSwitchGetter;
  164.             canFireThroughTargetGrid.Setter = canFireThroughTargetGridSwitchSetter;
  165.             canFireThroughTargetGrid.Title = MyStringId.GetOrCompute("Fire Through The Target Grid");
  166.             canFireThroughTargetGrid.Tooltip = MyStringId.GetOrCompute("Should the turret fire through other blocks on the target's grid to hit it's target");
  167.             canFireThroughTargetGrid.SupportsMultipleBlocks = true;
  168.             canFireThroughTargetGrid.OffText = MyStringId.GetOrCompute("False");
  169.             canFireThroughTargetGrid.OnText = MyStringId.GetOrCompute("True");
  170.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(canFireThroughTargetGrid);
  171.  
  172.             //CanFireThroughTargetGrid Action
  173.             var actionCanFireThroughTargetGrid = MyAPIGateway.TerminalControls.CreateAction<Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughTargetGridAction");
  174.             actionCanFireThroughTargetGrid.Action = canFireThroughTargetGridSwitchAction;
  175.             actionCanFireThroughTargetGrid.Name = new StringBuilder("Fire Through The Target Grid On/Off");
  176.             actionCanFireThroughTargetGrid.Writer = canFireThroughTargetGridSwitchWriter;
  177.             MyAPIGateway.TerminalControls.AddAction<Sandbox.ModAPI.IMyLargeTurretBase>(actionCanFireThroughTargetGrid);
  178.  
  179.             //ManhattanToleranceSlider
  180.             manhattanToleranceSlider = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSlider, Sandbox.ModAPI.IMyLargeTurretBase>("ManhattanToleranceSlider");
  181.             manhattanToleranceSlider.Getter = manhattanToleranceSliderGetter;
  182.             manhattanToleranceSlider.Setter = manhattanToleranceSliderSetter;
  183.             manhattanToleranceSlider.Title = MyStringId.GetOrCompute("Obstacle Block Tolerance");
  184.             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");
  185.             manhattanToleranceSlider.SupportsMultipleBlocks = true;
  186.             manhattanToleranceSlider.SetLimits(0, 10);
  187.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(manhattanToleranceSlider);
  188.  
  189.             //CanFireThroughHostiles
  190.             canFireThroughHostiles = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughHostiles");
  191.             canFireThroughHostiles.Getter = canFireThroughHostilesSwitchGetter;
  192.             canFireThroughHostiles.Setter = canFireThroughHostilesSwitchSetter;
  193.             canFireThroughHostiles.Title = MyStringId.GetOrCompute("Fire Through Hostile Grids");
  194.             canFireThroughHostiles.Tooltip = MyStringId.GetOrCompute("Should the turret fire through other hostile grids to hit it's target");
  195.             canFireThroughHostiles.SupportsMultipleBlocks = true;
  196.             canFireThroughHostiles.OffText = MyStringId.GetOrCompute("False");
  197.             canFireThroughHostiles.OnText = MyStringId.GetOrCompute("True");
  198.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(canFireThroughHostiles);
  199.  
  200.             //CanFireThroughHostiles Action
  201.             var actionCanFireThroughHostiles = MyAPIGateway.TerminalControls.CreateAction<Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughHostilesAction");
  202.             actionCanFireThroughHostiles.Action = canFireThroughHostilesSwitchAction;
  203.             actionCanFireThroughHostiles.Name = new StringBuilder("Fire Through Hostile Grids On/Off");
  204.             actionCanFireThroughHostiles.Writer = canFireThroughHostilesSwitchWriter;
  205.             MyAPIGateway.TerminalControls.AddAction<Sandbox.ModAPI.IMyLargeTurretBase>(actionCanFireThroughHostiles);
  206.  
  207.             //CanFireThroughNeutrals
  208.             canFireThroughNeutrals = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughNeutrals");
  209.             canFireThroughNeutrals.Getter = canFireThroughNeutralsSwitchGetter;
  210.             canFireThroughNeutrals.Setter = canFireThroughNeutralsSwitchSetter;
  211.             canFireThroughNeutrals.Title = MyStringId.GetOrCompute("Fire Through Neutrals Grids");
  212.             canFireThroughNeutrals.Tooltip = MyStringId.GetOrCompute("Should the turret fire through neutral grids to hit it's target");
  213.             canFireThroughNeutrals.SupportsMultipleBlocks = true;
  214.             canFireThroughNeutrals.OffText = MyStringId.GetOrCompute("False");
  215.             canFireThroughNeutrals.OnText = MyStringId.GetOrCompute("True");
  216.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(canFireThroughNeutrals);
  217.  
  218.             //CanFireThroughNeutrals Action
  219.             var actionCanFireThroughNeutrals = MyAPIGateway.TerminalControls.CreateAction<Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughNeutralsAction");
  220.             actionCanFireThroughNeutrals.Action = canFireThroughNeutralsSwitchAction;
  221.             actionCanFireThroughNeutrals.Name = new StringBuilder("Fire Through Neutral Grids On/Off");
  222.             actionCanFireThroughNeutrals.Writer = canFireThroughNeutralsSwitchWriter;
  223.             MyAPIGateway.TerminalControls.AddAction<Sandbox.ModAPI.IMyLargeTurretBase>(actionCanFireThroughNeutrals);
  224.  
  225.             //CanFireThroughFriendlies
  226.             canFireThroughFriendlies = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlOnOffSwitch, Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughFriendlies");
  227.             canFireThroughFriendlies.Getter = canFireThroughFriendliesSwitchGetter;
  228.             canFireThroughFriendlies.Setter = canFireThroughFriendliesSwitchSetter;
  229.             canFireThroughFriendlies.Title = MyStringId.GetOrCompute("Fire Through Friendly Grids");
  230.             canFireThroughFriendlies.SupportsMultipleBlocks = true;
  231.             canFireThroughFriendlies.Tooltip = MyStringId.GetOrCompute("Should the turret fire through friendly grids to hit it's target. WARNING: MAY INCLUDE TURRET'S GRID!");
  232.             canFireThroughFriendlies.OffText = MyStringId.GetOrCompute("False");
  233.             canFireThroughFriendlies.OnText = MyStringId.GetOrCompute("True");
  234.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(canFireThroughFriendlies);
  235.  
  236.             //CanFireThroughFriendlies Action
  237.             var actionCanFireThroughFriendlies = MyAPIGateway.TerminalControls.CreateAction<Sandbox.ModAPI.IMyLargeTurretBase>("CanFireThroughFriendliesAction");
  238.             actionCanFireThroughFriendlies.Action = canFireThroughFriendliesSwitchAction;
  239.             actionCanFireThroughFriendlies.Name = new StringBuilder("Fire Through Friendly Grids On/Off");
  240.             actionCanFireThroughFriendlies.Writer = canFireThroughFriendliesSwitchWriter;
  241.             MyAPIGateway.TerminalControls.AddAction<Sandbox.ModAPI.IMyLargeTurretBase>(actionCanFireThroughFriendlies);
  242.  
  243.             //MinTargetSizeSlider
  244.             minTargetSizeSlider = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSlider, Sandbox.ModAPI.IMyLargeTurretBase>("MinTargetSizeSlider");
  245.             minTargetSizeSlider.Getter = minTargetSizeSliderGetter;
  246.             minTargetSizeSlider.Setter = minTargetSizeSliderSetter;
  247.             minTargetSizeSlider.Title = MyStringId.GetOrCompute("Minimum Target Grid Size");
  248.             minTargetSizeSlider.Tooltip = MyStringId.GetOrCompute("Only blocks on grids equal to or greater than this value will be targeted");
  249.             minTargetSizeSlider.SupportsMultipleBlocks = true;
  250.             minTargetSizeSlider.SetLimits(0, 300);
  251.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(minTargetSizeSlider);
  252.  
  253.             //Divider
  254.             var divider3 = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSeparator, Sandbox.ModAPI.IMyLargeTurretBase>("Divider3");
  255.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(divider3);
  256.  
  257.             //Title
  258.             var titleTypes = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlLabel, Sandbox.ModAPI.IMyLargeTurretBase>("TitleTypes");
  259.             titleTypes.Label = MyStringId.GetOrCompute("Targeting Priorities");
  260.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(titleTypes);
  261.  
  262.             //TargetTypesEnableDisable
  263.             targetTypesEnableDisable = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlButton, Sandbox.ModAPI.IMyLargeTurretBase>("TargetTypesEnableDisable");
  264.             targetTypesEnableDisable.Action = targetTypesEnableDisableAction;
  265.             targetTypesEnableDisable.SupportsMultipleBlocks = false;
  266.             targetTypesEnableDisable.Title = MyStringId.GetOrCompute("Enable/Disable");
  267.             targetTypesEnableDisable.Tooltip = MyStringId.GetOrCompute("(+) == Enabled, (-) == Disabled");
  268.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(targetTypesEnableDisable);
  269.  
  270.             //TargetTypesPriorityUp
  271.             targetTypesPriorityUp = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlButton, Sandbox.ModAPI.IMyLargeTurretBase>("TargetTypesPriorityUp");
  272.             targetTypesPriorityUp.Action = targetTypesPriorityUpAction;
  273.             targetTypesPriorityUp.SupportsMultipleBlocks = false;
  274.             targetTypesPriorityUp.Title = MyStringId.GetOrCompute("Priority Up");
  275.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(targetTypesPriorityUp);
  276.  
  277.             //TargetTypesPriorityDown
  278.             targetTypesPriorityDown = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlButton, Sandbox.ModAPI.IMyLargeTurretBase>("TargetTypesPriorityDown");
  279.             targetTypesPriorityDown.Action = targetTypesPriorityDownAction;
  280.             targetTypesPriorityDown.SupportsMultipleBlocks = false;
  281.             targetTypesPriorityDown.Title = MyStringId.GetOrCompute("Priority Down");
  282.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(targetTypesPriorityDown);
  283.  
  284.             //TargetTypesList
  285.             targetTypesList = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlListbox, Sandbox.ModAPI.IMyLargeTurretBase>("TargetTypesList");
  286.             targetTypesList.ListContent = targetTypesListPopulator;
  287.             targetTypesList.ItemSelected = targetTypesListSelector;
  288.             targetTypesList.SupportsMultipleBlocks = false;
  289.             targetTypesList.Multiselect = false;
  290.             targetTypesList.VisibleRowsCount = 29;
  291.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(targetTypesList);
  292.  
  293.             //Divider
  294.             var divider4 = MyAPIGateway.TerminalControls.CreateControl<IMyTerminalControlSeparator, Sandbox.ModAPI.IMyLargeTurretBase>("Divider4");
  295.             MyAPIGateway.TerminalControls.AddControl<Sandbox.ModAPI.IMyLargeTurretBase>(divider4);
  296.         }
  297.  
  298.         //SmartTargetingSwitch Setter/Getter/Action
  299.         bool smartTargetingSwitchGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
  300.             IMyEntity thisBlock = turret as IMyEntity;
  301.             var Nulled = "";
  302.  
  303.             if (thisBlock.Storage == null) {
  304.                 thisBlock.Storage = new MyModStorageComponent();
  305.                 thisBlock.Storage[myGUID1] = "false";
  306.                 return false;
  307.             } else if (thisBlock.Storage.TryGetValue(myGUID1, out Nulled) == false) {
  308.                 thisBlock.Storage[myGUID1] = "false";
  309.                 return false;
  310.             } else {
  311.                 return bool.Parse(thisBlock.Storage[myGUID1]);
  312.             }
  313.         }
  314.  
  315.         void smartTargetingSwitchSetter(Sandbox.ModAPI.IMyTerminalBlock turret, bool newValue) {
  316.             IMyEntity thisBlock = turret as IMyEntity;
  317.  
  318.             if (thisBlock.Storage == null) {
  319.                 thisBlock.Storage = new MyModStorageComponent();
  320.             }
  321.  
  322.             thisBlock.Storage[myGUID1] = newValue.ToString();
  323.  
  324.             turret.ApplyAction("Shoot_Off");
  325.  
  326.             if (newValue) {
  327.                 if (turret.HasAction("TargetMeteors_Off")) {
  328.                     turret.ApplyAction("TargetMeteors_Off");
  329.                 }
  330.                 if (turret.HasAction("TargetMissiles_Off")) {
  331.                     turret.ApplyAction("TargetMissiles_Off");
  332.                 }
  333.                 if (turret.HasAction("TargetSmallShips_Off")) {
  334.                     turret.ApplyAction("TargetSmallShips_Off");
  335.                 }
  336.                 if (turret.HasAction("TargetLargeShips_Off")) {
  337.                     turret.ApplyAction("TargetLargeShips_Off");
  338.                 }
  339.                 if (turret.HasAction("TargetCharacters_Off")) {
  340.                     turret.ApplyAction("TargetCharacters_Off");
  341.                 }
  342.                 if (turret.HasAction("TargetStations_Off")) {
  343.                     turret.ApplyAction("TargetStations_Off");
  344.                 }
  345.             }
  346.         }
  347.  
  348.         void smartTargetingSwitchAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
  349.             IMyEntity thisBlock = turret as IMyEntity;
  350.             var Nulled = "";
  351.  
  352.             if (thisBlock.Storage == null) {
  353.                 smartTargetingSwitchSetter(turret, true);
  354.             } else if (thisBlock.Storage.TryGetValue(myGUID1, out Nulled) == false) {
  355.                 smartTargetingSwitchSetter(turret, true);
  356.             } else {
  357.                 smartTargetingSwitchSetter(turret, !bool.Parse(thisBlock.Storage[myGUID1]));
  358.             }
  359.         }
  360.  
  361.         void SmartTargetingSwitchWriter(Sandbox.ModAPI.IMyTerminalBlock turret, StringBuilder text) {
  362.             text.Clear();
  363.  
  364.             if (smartTargetingSwitchGetter(turret)) {
  365.                 text.Append("On");
  366.             } else {
  367.                 text.Append("Off");
  368.             }
  369.         }
  370.  
  371.         //------------------------------------------------------------------------------
  372.  
  373.         //trackTargetSwitch Setter/Getter
  374.         bool trackTargetSwitchGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
  375.             IMyEntity thisBlock = turret as IMyEntity;
  376.             var Nulled = "";
  377.  
  378.             if (thisBlock.Storage == null) {
  379.                 thisBlock.Storage = new MyModStorageComponent();
  380.                 thisBlock.Storage[myGUID9] = "true";
  381.                 return true;
  382.             } else if (thisBlock.Storage.TryGetValue(myGUID9, out Nulled) == false) {
  383.                 thisBlock.Storage[myGUID9] = "true";
  384.                 return true;
  385.             } else {
  386.                 return bool.Parse(thisBlock.Storage[myGUID9]);
  387.             }
  388.         }
  389.  
  390.         void trackTargetSwitchSetter(Sandbox.ModAPI.IMyTerminalBlock turret, bool newValue) {
  391.             IMyEntity thisBlock = turret as IMyEntity;
  392.             if (thisBlock.Storage == null) {
  393.                 thisBlock.Storage = new MyModStorageComponent();
  394.             }
  395.             thisBlock.Storage[myGUID9] = newValue.ToString();
  396.         }
  397.  
  398.         void trackTargetSwitchAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
  399.             IMyEntity thisBlock = turret as IMyEntity;
  400.             var Nulled = "";
  401.  
  402.             if (thisBlock.Storage == null) {
  403.                 trackTargetSwitchSetter(turret, true);
  404.             } else if (thisBlock.Storage.TryGetValue(myGUID9, out Nulled) == false) {
  405.                 trackTargetSwitchSetter(turret, true);
  406.             } else {
  407.                 trackTargetSwitchSetter(turret, !bool.Parse(thisBlock.Storage[myGUID9]));
  408.             }
  409.         }
  410.  
  411.         void trackTargetSwitchWriter(Sandbox.ModAPI.IMyTerminalBlock turret, StringBuilder text) {
  412.             text.Clear();
  413.  
  414.             if (trackTargetSwitchGetter(turret)) {
  415.                 text.Append("On");
  416.             } else {
  417.                 text.Append("Off");
  418.             }
  419.         }
  420.  
  421.         //------------------------------------------------------------------------------
  422.  
  423.         //ManhattanToleranceSlider Setter/Getter
  424.         float smartTargetRangeSliderGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
  425.             IMyEntity thisBlock = turret as IMyEntity;
  426.             var Nulled = "";
  427.  
  428.             if (thisBlock.Storage == null) {
  429.                 thisBlock.Storage = new MyModStorageComponent();
  430.                 thisBlock.Storage[myGUID11] = "800";
  431.                 return 800;
  432.             } else if (thisBlock.Storage.TryGetValue(myGUID11, out Nulled) == false) {
  433.                 thisBlock.Storage[myGUID11] = "800";
  434.                 return 800;
  435.             } else {
  436.                 return float.Parse(thisBlock.Storage[myGUID11]);
  437.             }
  438.         }
  439.  
  440.         void smartTargetRangeSliderSetter(Sandbox.ModAPI.IMyTerminalBlock turret, float newValue) {
  441.             IMyEntity thisBlock = turret as IMyEntity;
  442.             if (thisBlock.Storage == null) {
  443.                 thisBlock.Storage = new MyModStorageComponent();
  444.             }
  445.  
  446.             thisBlock.Storage[myGUID11] = newValue.ToString();
  447.             smartTargetRange.UpdateVisual();
  448.         }
  449.  
  450.         //------------------------------------------------------------------------------
  451.  
  452.         //CanFireThroughTargetGrid Setter/Getter
  453.         bool canFireThroughTargetGridSwitchGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
  454.             IMyEntity thisBlock = turret as IMyEntity;
  455.             var Nulled = "";
  456.  
  457.             if (thisBlock.Storage == null) {
  458.                 thisBlock.Storage = new MyModStorageComponent();
  459.                 thisBlock.Storage[myGUID6] = "false";
  460.                 return false;
  461.             } else if (thisBlock.Storage.TryGetValue(myGUID6, out Nulled) == false) {
  462.                 thisBlock.Storage[myGUID6] = "false";
  463.                 return false;
  464.             } else {
  465.                 return bool.Parse(thisBlock.Storage[myGUID6]);
  466.             }
  467.         }
  468.  
  469.         void canFireThroughTargetGridSwitchSetter(Sandbox.ModAPI.IMyTerminalBlock turret, bool newValue) {
  470.             IMyEntity thisBlock = turret as IMyEntity;
  471.             if (thisBlock.Storage == null) {
  472.                 thisBlock.Storage = new MyModStorageComponent();
  473.             }
  474.             thisBlock.Storage[myGUID6] = newValue.ToString();
  475.  
  476.             if (newValue == true) {
  477.                 manhattanToleranceSlider.Enabled = (block) => false;
  478.                 manhattanToleranceSlider.UpdateVisual();
  479.             } else {
  480.                 manhattanToleranceSlider.Enabled = (block) => true;
  481.                 manhattanToleranceSlider.UpdateVisual();
  482.             }
  483.         }
  484.  
  485.         void canFireThroughTargetGridSwitchAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
  486.             IMyEntity thisBlock = turret as IMyEntity;
  487.             var Nulled = "";
  488.  
  489.             if (thisBlock.Storage == null) {
  490.                 canFireThroughTargetGridSwitchSetter(turret, true);
  491.             } else if (thisBlock.Storage.TryGetValue(myGUID6, out Nulled) == false) {
  492.                 canFireThroughTargetGridSwitchSetter(turret, true);
  493.             } else {
  494.                 canFireThroughTargetGridSwitchSetter(turret, !bool.Parse(thisBlock.Storage[myGUID6]));
  495.             }
  496.         }
  497.  
  498.         void canFireThroughTargetGridSwitchWriter(Sandbox.ModAPI.IMyTerminalBlock turret, StringBuilder text) {
  499.             text.Clear();
  500.  
  501.             if (canFireThroughTargetGridSwitchGetter(turret)) {
  502.                 text.Append("On");
  503.             } else {
  504.                 text.Append("Off");
  505.             }
  506.         }
  507.  
  508.         //------------------------------------------------------------------------------
  509.  
  510.         //ManhattanToleranceSlider Setter/Getter
  511.         float manhattanToleranceSliderGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
  512.             IMyEntity thisBlock = turret as IMyEntity;
  513.             var Nulled = "";
  514.  
  515.             if (thisBlock.Storage.TryGetValue(myGUID6, out Nulled) == true) {
  516.                 if (bool.Parse(thisBlock.Storage[myGUID6])) {
  517.                     manhattanToleranceSlider.Enabled = (block) => false;
  518.                 } else {
  519.                     manhattanToleranceSlider.Enabled = (block) => true;
  520.                 }
  521.             }
  522.  
  523.             if (thisBlock.Storage == null) {
  524.                 thisBlock.Storage = new MyModStorageComponent();
  525.                 thisBlock.Storage[myGUID10] = "3";
  526.                 return 3;
  527.             } else if (thisBlock.Storage.TryGetValue(myGUID10, out Nulled) == false) {
  528.                 thisBlock.Storage[myGUID10] = "3";
  529.                 return 3;
  530.             } else {
  531.                 return float.Parse(thisBlock.Storage[myGUID10]);
  532.             }
  533.         }
  534.  
  535.         void manhattanToleranceSliderSetter(Sandbox.ModAPI.IMyTerminalBlock turret, float newValue) {
  536.             IMyEntity thisBlock = turret as IMyEntity;
  537.             if (thisBlock.Storage == null) {
  538.                 thisBlock.Storage = new MyModStorageComponent();
  539.             }
  540.  
  541.             thisBlock.Storage[myGUID10] = Math.Floor(newValue).ToString();
  542.             manhattanToleranceSlider.UpdateVisual();
  543.         }
  544.  
  545.         //------------------------------------------------------------------------------
  546.  
  547.         //CanFireThroughHostiles Setter/Getter
  548.         bool canFireThroughHostilesSwitchGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
  549.             IMyEntity thisBlock = turret as IMyEntity;
  550.             var Nulled = "";
  551.  
  552.             if (thisBlock.Storage == null) {
  553.                 thisBlock.Storage = new MyModStorageComponent();
  554.                 thisBlock.Storage[myGUID3] = "false";
  555.                 return false;
  556.             } else if (thisBlock.Storage.TryGetValue(myGUID3, out Nulled) == false) {
  557.                 thisBlock.Storage[myGUID3] = "false";
  558.                 return false;
  559.             } else {
  560.                 return bool.Parse(thisBlock.Storage[myGUID3]);
  561.             }
  562.         }
  563.  
  564.         void canFireThroughHostilesSwitchSetter(Sandbox.ModAPI.IMyTerminalBlock turret, bool newValue) {
  565.             IMyEntity thisBlock = turret as IMyEntity;
  566.             if (thisBlock.Storage == null) {
  567.                 thisBlock.Storage = new MyModStorageComponent();
  568.             }
  569.             thisBlock.Storage[myGUID3] = newValue.ToString();
  570.         }
  571.  
  572.         void canFireThroughHostilesSwitchAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
  573.             IMyEntity thisBlock = turret as IMyEntity;
  574.             var Nulled = "";
  575.  
  576.             if (thisBlock.Storage == null) {
  577.                 canFireThroughHostilesSwitchSetter(turret, true);
  578.             } else if (thisBlock.Storage.TryGetValue(myGUID3, out Nulled) == false) {
  579.                 canFireThroughHostilesSwitchSetter(turret, true);
  580.             } else {
  581.                 canFireThroughHostilesSwitchSetter(turret, !bool.Parse(thisBlock.Storage[myGUID3]));
  582.             }
  583.         }
  584.  
  585.         void canFireThroughHostilesSwitchWriter(Sandbox.ModAPI.IMyTerminalBlock turret, StringBuilder text) {
  586.             text.Clear();
  587.  
  588.             if (canFireThroughHostilesSwitchGetter(turret)) {
  589.                 text.Append("On");
  590.             } else {
  591.                 text.Append("Off");
  592.             }
  593.         }
  594.  
  595.         //------------------------------------------------------------------------------
  596.  
  597.         //CanFireThroughNeutrals Setter/Getter
  598.         bool canFireThroughNeutralsSwitchGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
  599.             IMyEntity thisBlock = turret as IMyEntity;
  600.             var Nulled = "";
  601.  
  602.             if (thisBlock.Storage == null) {
  603.                 thisBlock.Storage = new MyModStorageComponent();
  604.                 thisBlock.Storage[myGUID4] = "false";
  605.                 return false;
  606.             } else if (thisBlock.Storage.TryGetValue(myGUID4, out Nulled) == false) {
  607.                 thisBlock.Storage[myGUID4] = "false";
  608.                 return false;
  609.             } else {
  610.                 return bool.Parse(thisBlock.Storage[myGUID4]);
  611.             }
  612.         }
  613.  
  614.         void canFireThroughNeutralsSwitchSetter(Sandbox.ModAPI.IMyTerminalBlock turret, bool newValue) {
  615.             IMyEntity thisBlock = turret as IMyEntity;
  616.             if (thisBlock.Storage == null) {
  617.                 thisBlock.Storage = new MyModStorageComponent();
  618.             }
  619.             thisBlock.Storage[myGUID4] = newValue.ToString();
  620.         }
  621.  
  622.         void canFireThroughNeutralsSwitchAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
  623.             IMyEntity thisBlock = turret as IMyEntity;
  624.             var Nulled = "";
  625.  
  626.             if (thisBlock.Storage == null) {
  627.                 canFireThroughNeutralsSwitchSetter(turret, true);
  628.             } else if (thisBlock.Storage.TryGetValue(myGUID4, out Nulled) == false) {
  629.                 canFireThroughNeutralsSwitchSetter(turret, true);
  630.             } else {
  631.                 canFireThroughNeutralsSwitchSetter(turret, !bool.Parse(thisBlock.Storage[myGUID4]));
  632.             }
  633.         }
  634.  
  635.         void canFireThroughNeutralsSwitchWriter(Sandbox.ModAPI.IMyTerminalBlock turret, StringBuilder text) {
  636.             text.Clear();
  637.  
  638.             if (canFireThroughNeutralsSwitchGetter(turret)) {
  639.                 text.Append("On");
  640.             } else {
  641.                 text.Append("Off");
  642.             }
  643.         }
  644.  
  645.         //------------------------------------------------------------------------------
  646.  
  647.         //CanFireThroughFriendlies Setter/Getter
  648.         bool canFireThroughFriendliesSwitchGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
  649.             IMyEntity thisBlock = turret as IMyEntity;
  650.             var Nulled = "";
  651.  
  652.             if (thisBlock.Storage == null) {
  653.                 thisBlock.Storage = new MyModStorageComponent();
  654.                 thisBlock.Storage[myGUID5] = "false";
  655.                 return false;
  656.             } else if (thisBlock.Storage.TryGetValue(myGUID5, out Nulled) == false) {
  657.                 thisBlock.Storage[myGUID5] = "false";
  658.                 return false;
  659.             } else {
  660.                 return bool.Parse(thisBlock.Storage[myGUID5]);
  661.             }
  662.         }
  663.  
  664.         void canFireThroughFriendliesSwitchSetter(Sandbox.ModAPI.IMyTerminalBlock turret, bool newValue) {
  665.             IMyEntity thisBlock = turret as IMyEntity;
  666.             if (thisBlock.Storage == null) {
  667.                 thisBlock.Storage = new MyModStorageComponent();
  668.             }
  669.             thisBlock.Storage[myGUID5] = newValue.ToString();
  670.         }
  671.  
  672.         void canFireThroughFriendliesSwitchAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
  673.             IMyEntity thisBlock = turret as IMyEntity;
  674.             var Nulled = "";
  675.  
  676.             if (thisBlock.Storage == null) {
  677.                 canFireThroughFriendliesSwitchSetter(turret, true);
  678.             } else if (thisBlock.Storage.TryGetValue(myGUID5, out Nulled) == false) {
  679.                 canFireThroughFriendliesSwitchSetter(turret, true);
  680.             } else {
  681.                 canFireThroughFriendliesSwitchSetter(turret, !bool.Parse(thisBlock.Storage[myGUID5]));
  682.             }
  683.         }
  684.  
  685.         void canFireThroughFriendliesSwitchWriter(Sandbox.ModAPI.IMyTerminalBlock turret, StringBuilder text) {
  686.             text.Clear();
  687.  
  688.             if (canFireThroughFriendliesSwitchGetter(turret)) {
  689.                 text.Append("On");
  690.             } else {
  691.                 text.Append("Off");
  692.             }
  693.         }
  694.  
  695.         //------------------------------------------------------------------------------
  696.  
  697.         //MinTargetSizeSlider Setter/Getter
  698.         float minTargetSizeSliderGetter(Sandbox.ModAPI.IMyTerminalBlock turret) {
  699.             IMyEntity thisBlock = turret as IMyEntity;
  700.             var Nulled = "";
  701.  
  702.             if (thisBlock.Storage == null) {
  703.                 thisBlock.Storage = new MyModStorageComponent();
  704.                 thisBlock.Storage[myGUID2] = "0";
  705.                 return 0;
  706.             } else if (thisBlock.Storage.TryGetValue(myGUID2, out Nulled) == false) {
  707.                 thisBlock.Storage[myGUID2] = "0";
  708.                 return 0;
  709.             } else {
  710.                 return float.Parse(thisBlock.Storage[myGUID2]);
  711.             }
  712.         }
  713.  
  714.         void minTargetSizeSliderSetter(Sandbox.ModAPI.IMyTerminalBlock turret, float newValue) {
  715.             IMyEntity thisBlock = turret as IMyEntity;
  716.             if (thisBlock.Storage == null) {
  717.                 thisBlock.Storage = new MyModStorageComponent();
  718.             }
  719.  
  720.             thisBlock.Storage[myGUID2] = Math.Floor(newValue).ToString();
  721.             minTargetSizeSlider.UpdateVisual();
  722.         }
  723.  
  724.         //------------------------------------------------------------------------------
  725.  
  726.         //TargetTypesEnableDisable Action
  727.         void targetTypesEnableDisableAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
  728.             IMyEntity thisBlock = turret as IMyEntity;
  729.             string storage = "";
  730.             string[] storage1 = thisBlock.Storage[myGUID7].Split('/');
  731.             string storage2 = thisBlock.Storage[myGUID8];
  732.             List<MyTerminalControlListBoxItem> itemList = new List<MyTerminalControlListBoxItem>();
  733.  
  734.             for (var i = 0; i < storage1.Length; i++) {
  735.                 if (i % 2 != 0) {
  736.                     itemList.Add(new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(storage1[i - 1]), MyStringId.GetOrCompute(storage1[i]), null));
  737.                 }
  738.             }
  739.  
  740.             foreach (var item1 in itemList) {
  741.                 if (item1.Text.String == storage2) {
  742.                     if (item1.Text.String.Contains("+")) {
  743.                         item1.Text = MyStringId.GetOrCompute(item1.Text.String.Replace('+', '-'));
  744.                         thisBlock.Storage[myGUID8] = item1.Text.String;
  745.                     } else {
  746.                         item1.Text = MyStringId.GetOrCompute(item1.Text.String.Replace('-', '+'));
  747.                         thisBlock.Storage[myGUID8] = item1.Text.String;
  748.                     }
  749.                     break;
  750.                 }
  751.             }
  752.  
  753.             foreach (var item2 in itemList) {
  754.                 storage += item2.Text + "/" + item2.Tooltip + "/";
  755.             }
  756.             thisBlock.Storage[myGUID7] = storage.Remove(storage.Length - 1);
  757.  
  758.             targetTypesList.UpdateVisual();
  759.         }
  760.  
  761.         //------------------------------------------------------------------------------
  762.  
  763.         //targetTypesPriorityUp Action
  764.         void targetTypesPriorityUpAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
  765.             IMyEntity thisBlock = turret as IMyEntity;
  766.  
  767.             string[] storage1 = thisBlock.Storage[myGUID7].Split('/');
  768.             string storage2 = thisBlock.Storage[myGUID8].Substring(4);
  769.             string temp1 = "";
  770.             string temp2 = "";
  771.  
  772.             for (int i = 0; i < storage1.Length; i++) {
  773.                 if (storage1[i].Substring(4) == storage2 && i > 1) {
  774.                     temp1 = storage1[i - 2];
  775.                     temp2 = storage1[i - 1];
  776.  
  777.                     storage1[i - 2] = storage1[i];
  778.                     storage1[i - 1] = storage1[i + 1];
  779.  
  780.                     storage1[i] = temp1;
  781.                     storage1[i + 1] = temp2;
  782.  
  783.                     break;
  784.                 }
  785.             }
  786.  
  787.             thisBlock.Storage[myGUID7] = string.Join("/", storage1);
  788.             targetTypesList.UpdateVisual();
  789.         }
  790.  
  791.         //------------------------------------------------------------------------------
  792.  
  793.         //targetTypesPriorityDown Action
  794.         void targetTypesPriorityDownAction(Sandbox.ModAPI.IMyTerminalBlock turret) {
  795.             IMyEntity thisBlock = turret as IMyEntity;
  796.  
  797.             string[] storage1 = thisBlock.Storage[myGUID7].Split('/');
  798.             string storage2 = thisBlock.Storage[myGUID8].Substring(4);
  799.             string temp1 = "";
  800.             string temp2 = "";
  801.  
  802.             for (int i = 0; i < storage1.Length; i++) {
  803.                 if (storage1[i].Substring(4) == storage2 && i < storage1.Length - 3) {
  804.                     temp1 = storage1[i + 2];
  805.                     temp2 = storage1[i + 3];
  806.  
  807.                     storage1[i + 2] = storage1[i];
  808.                     storage1[i + 3] = storage1[i + 1];
  809.  
  810.                     storage1[i] = temp1;
  811.                     storage1[i + 1] = temp2;
  812.  
  813.                     break;
  814.                 }
  815.             }
  816.  
  817.             thisBlock.Storage[myGUID7] = string.Join("/", storage1);
  818.             targetTypesList.UpdateVisual();
  819.         }
  820.  
  821.         //------------------------------------------------------------------------------
  822.  
  823.         //TargetTypesList Populator/Selector
  824.         void targetTypesListPopulator(Sandbox.ModAPI.IMyTerminalBlock turret, List<MyTerminalControlListBoxItem> itemList, List<MyTerminalControlListBoxItem> selectedItemList) {
  825.             IMyEntity thisBlock = turret as IMyEntity;
  826.             var Nulled = "";
  827.  
  828.             if (thisBlock.Storage == null) {
  829.                 thisBlock.Storage = new MyModStorageComponent();
  830.                 string storage = "";
  831.  
  832.                 foreach (var item in _items) {
  833.                     storage += item.Text + "/" + item.Tooltip + "/";
  834.                     itemList.Add(item);
  835.                 }
  836.                 thisBlock.Storage[myGUID7] = storage.Remove(storage.Length - 1);
  837.                 thisBlock.Storage[myGUID8] = "";
  838.                 return;
  839.             } else if (thisBlock.Storage.TryGetValue(myGUID7, out Nulled) == false) {
  840.                 string storage = "";
  841.  
  842.                 foreach (var item in _items) {
  843.                     storage += item.Text + "/" + item.Tooltip + "/";
  844.                     itemList.Add(item);
  845.                 }
  846.                 thisBlock.Storage[myGUID7] = storage.Remove(storage.Length - 1);
  847.                 thisBlock.Storage[myGUID8] = "";
  848.                 return;
  849.             } else {
  850.                 string[] storage1 = thisBlock.Storage[myGUID7].Split('/');
  851.  
  852.                 for (var i = 0; i < storage1.Length; i++) {
  853.                     if (i % 2 != 0) {
  854.                         itemList.Add(new MyTerminalControlListBoxItem(MyStringId.GetOrCompute(storage1[i - 1]), MyStringId.GetOrCompute(storage1[i]), null));
  855.                     }
  856.                 }
  857.  
  858.                 selectedItemList.Clear();
  859.  
  860.                 foreach (var item in itemList) {
  861.                     if (item.Text.String == thisBlock.Storage[myGUID8]) {
  862.                         selectedItemList.Add(item);
  863.                     }
  864.                 }
  865.                 return;
  866.             }
  867.         }
  868.  
  869.         void targetTypesListSelector(Sandbox.ModAPI.IMyTerminalBlock turret, List<MyTerminalControlListBoxItem> selectedItemList) {
  870.             IMyEntity thisBlock = turret as IMyEntity;
  871.  
  872.             if (selectedItemList.Count != 0) {
  873.                 thisBlock.Storage[myGUID8] = selectedItemList[0].Text.String;
  874.             }
  875.         }
  876.     }
  877. }
Advertisement
Add Comment
Please, Sign In to add comment