Advertisement
Meridius_IX

Barnacle Drone

Sep 2nd, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.41 KB | None | 0 0
  1. //Meridius_IX's Pirate AI Systems
  2.  
  3. double player_detect_range = 20000; //If player is further than this value from drone, it will not execute any behavioral scripting.
  4.  
  5. //////////////////////////////////////////////////////
  6. //Do Not Touch Anything Below Here
  7. //////////////////////////////////////////////////////
  8.  
  9. double player_drone_distance = 0;
  10. double player_origin_distance = 0;
  11. double drone_origin_distance = 0;
  12.  
  13. //Raycast Scan Data
  14. MyDetectedEntityInfo scanned_target;
  15. bool valid_scanned_target = false;
  16. double scanned_target_distance = 0;
  17. Vector3D scanned_target_coords = new Vector3D(0,0,0);
  18.  
  19. IMyRemoteControl remote_control;
  20. IMyRadioAntenna antenna;
  21. IMyWarhead warhead;
  22.  
  23. void Main(string argument){
  24.    
  25.     Vector3D world_center = new Vector3D(0,0,0);
  26.     Vector3D player_coords = new Vector3D(0,0,0);
  27.     Vector3D drone_coords = new Vector3D(0,0,0);
  28.     Vector3D origin_coords = new Vector3D(0,0,0);
  29.    
  30.     //Find Remote Control Block(s)
  31.     List<IMyTerminalBlock> remote_control_list = new List<IMyTerminalBlock>();
  32.     GridTerminalSystem.GetBlocksOfType<IMyRemoteControl>(remote_control_list);
  33.    
  34.     if(remote_control_list.Count != 0){
  35.        
  36.         for(int i = 0; i < remote_control_list.Count; i++){
  37.            
  38.             if(remote_control_list[i].IsFunctional == true){
  39.                
  40.                 remote_control = remote_control_list[i] as IMyRemoteControl;
  41.                 break;
  42.                
  43.             }
  44.            
  45.         }
  46.        
  47.     }else{
  48.        
  49.         Echo("No Remote Control Block Found. Script Cannot Execute.");
  50.         return;
  51.        
  52.     }
  53.    
  54.     //Check If Drone is NPC Owned
  55.     remote_control.GetNearestPlayer(out player_coords);
  56.    
  57.     if(player_coords == world_center){
  58.        
  59.         Echo("Drone is not owned by Hostile NPC. Script Cannot Continue.");
  60.         return;
  61.        
  62.     }
  63.    
  64.     drone_coords = remote_control.GetPosition();
  65.     valid_scanned_target = RaycastScan();
  66.    
  67.     //Get & Set Origin Coords
  68.     if(this.Storage == null || this.Storage == ""){
  69.        
  70.         this.Storage = drone_coords.ToString();
  71.         origin_coords = drone_coords;
  72.        
  73.     }else{
  74.        
  75.         Vector3D.TryParse(this.Storage, out origin_coords);
  76.        
  77.     }
  78.    
  79.     //Calculate Distances
  80.     player_drone_distance = MeasureDistance(player_coords, drone_coords);
  81.     player_origin_distance = MeasureDistance(player_coords, origin_coords);
  82.     drone_origin_distance = MeasureDistance(drone_coords, origin_coords);
  83.     scanned_target_distance = MeasureDistance(drone_coords, scanned_target_coords);
  84.  
  85.     if(player_drone_distance > player_detect_range){
  86.        
  87.         Echo("No Player Detected. Aborting Script Execution.");
  88.        
  89.     }
  90.    
  91.     //////////////////////////////////////////////////////
  92.     //Pirate Behavior Start
  93.     //////////////////////////////////////////////////////
  94.    
  95.     List<IMyTerminalBlock> antenna_list = new List<IMyTerminalBlock>();
  96.     GridTerminalSystem.GetBlocksOfType<IMyRadioAntenna>(antenna_list);
  97.     antenna = null;
  98.     bool gear_locked = LandingGearCheck();
  99.    
  100.     if(antenna_list.Count != 0){
  101.        
  102.         for(int i = 0; i < antenna_list.Count; i++){
  103.            
  104.             if(antenna_list[i].IsFunctional == true){
  105.                
  106.                 antenna = antenna_list[i] as IMyRadioAntenna;
  107.                 break;
  108.                
  109.             }
  110.            
  111.         }
  112.        
  113.     }
  114.    
  115.    
  116.     if(player_drone_distance < 100){
  117.            
  118.             remote_control.ApplyAction("DockingMode_Off");
  119.            
  120.         }else{
  121.            
  122.             remote_control.ApplyAction("DockingMode_Off");
  123.            
  124.         }
  125.    
  126.     if(valid_scanned_target == true){
  127.        
  128.         remote_control.ClearWaypoints();
  129.         remote_control.AddWaypoint(scanned_target_coords, "Target");
  130.         remote_control.SetAutoPilotEnabled(true);      
  131.        
  132.     }else{
  133.        
  134.         remote_control.ClearWaypoints();
  135.         remote_control.AddWaypoint(player_coords, "Player");
  136.         remote_control.SetAutoPilotEnabled(true);
  137.        
  138.     }
  139.    
  140.     //Reinforcements
  141.     if(antenna != null && valid_scanned_target == true && gear_locked == true){
  142.        
  143.         antenna.ApplyAction("OnOff_On");
  144.         antenna.SetValueBool("EnableBroadCast", true);
  145.         antenna.CustomName = "Target Contact Confirmed";
  146.            
  147.     }
  148.    
  149.     //Explode Drone
  150.     bool getting_hacked = HackingDetection();
  151.     if(antenna != null || getting_hacked == true){
  152.        
  153.         BlockActivation("Warheads");
  154.            
  155.     }
  156.    
  157.     //////////////////////////////////////////////////////
  158.     //Pirate Behavior End
  159.     //////////////////////////////////////////////////////
  160.    
  161. }
  162.  
  163. bool RaycastScan(){
  164.    
  165.     List<IMyTerminalBlock> camera_list = new List<IMyTerminalBlock>();
  166.     GridTerminalSystem.GetBlocksOfType<IMyCameraBlock>(camera_list);
  167.    
  168.     if(camera_list.Count != 0){
  169.        
  170.         for(int i = 0; i < camera_list.Count; i++){
  171.            
  172.             IMyCameraBlock camera = camera_list[i] as IMyCameraBlock;
  173.            
  174.             if(camera.IsFunctional == true){
  175.                
  176.                 camera.EnableRaycast = true;
  177.                
  178.                 if(camera.CanScan(1600)){
  179.                    
  180.                     scanned_target = camera.Raycast(1600, 0, 0);
  181.                    
  182.                     if(scanned_target.Relationship.ToString() != "Owner" || scanned_target.Relationship.ToString() != "FactionShare"){
  183.                        
  184.                         if(scanned_target.Type.ToString() == "LargeGrid" || scanned_target.Type.ToString() == "SmallGrid" || scanned_target.Type.ToString() == "CharacterHuman"){
  185.                            
  186.                             scanned_target_coords = (Vector3D)scanned_target.HitPosition;
  187.                             return true;
  188.                            
  189.                         }
  190.                        
  191.                     }
  192.                    
  193.                 }
  194.                
  195.             }
  196.            
  197.         }
  198.        
  199.     }else{
  200.    
  201.         Echo("No Camera Block Found. Cannot Do Raycast Scan.");
  202.         return false;
  203.        
  204.     }
  205.    
  206.     return false;
  207.    
  208. }
  209.  
  210. bool HackingDetection(){
  211.    
  212.     List<IMyTerminalBlock> all_blocks = new List<IMyTerminalBlock>();
  213.     GridTerminalSystem.GetBlocksOfType<IMyTerminalBlock>(all_blocks);
  214.     for(int i = 0; i < all_blocks.Count; i++){
  215.        
  216.         if(all_blocks[i].IsBeingHacked == true){
  217.            
  218.             return true;
  219.            
  220.         }
  221.        
  222.     }
  223.    
  224.     return false;
  225.  
  226. }
  227.  
  228.  
  229. void BlockActivation(string blocks){
  230.    
  231.     if(blocks == "Warheads"){
  232.        
  233.         List<IMyTerminalBlock> warhead_list = new List<IMyTerminalBlock>();
  234.         GridTerminalSystem.GetBlocksOfType<IMyWarhead>(warhead_list);
  235.         for(int i = 0; i < warhead_list.Count; i++){
  236.            
  237.             warhead = warhead_list[i] as IMyWarhead;
  238.             warhead.ApplyAction("Detonate");
  239.            
  240.         }
  241.        
  242.     }
  243.    
  244. }
  245.  
  246.  
  247. bool LandingGearCheck(){
  248.    
  249.     List<IMyTerminalBlock> landing_gear_list = new List<IMyTerminalBlock>();
  250.     GridTerminalSystem.GetBlocksOfType<IMyLandingGear>(landing_gear_list);
  251.    
  252.     if(landing_gear_list.Count != 0){
  253.        
  254.         for(int i = 0; i < landing_gear_list.Count; i++){
  255.            
  256.             IMyLandingGear landing_gear = landing_gear_list[i] as IMyLandingGear;
  257.             if(landing_gear.IsLocked == true){
  258.                
  259.                 return true;
  260.                
  261.             }
  262.            
  263.         }
  264.        
  265.     }
  266.    
  267.     return false;
  268.    
  269. }
  270.  
  271. double MeasureDistance(Vector3D point_a, Vector3D point_b){
  272.    
  273.     double result = Math.Round( Vector3D.Distance( point_a, point_b ), 2 );
  274.     return result;
  275.    
  276. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement