Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 54.34 KB | None | 0 0
  1. // COPY FROM HERE
  2.  
  3. #region Introduction
  4. /*
  5. Introduction
  6. ----------------
  7. Hello and thank you for downloading Rdav's Fleet Command Beta
  8. Rdav's fleet command is a total-conversion code for automatic fleets.
  9. This code allows for artificially intelligent drone operation, drones
  10. adopt unique and intelligent behaviour allowing them to engage targets
  11. follow commands, dock, undock along with giving players advanced
  12. control capabilities for an entire amarda.
  13. Please see the workshop page for more details;
  14.  
  15. You are currently looking at the 'Central Command' Unit, which
  16. is the main hub of operations for the code, only ONE of these units
  17. should be used per-fleet, others can be kept as backups, but only one
  18. should be operational at any one time.
  19.  
  20. Rdav 28/08/17
  21.  
  22. Installation
  23. --------------
  24. The code should come in a Pre-Fab format to make installation a breeze.
  25. Setup of these modules manually can be achieved however for streamlining
  26. or otherwise making the components of the module smaller, please refer to
  27. the manual to do so.
  28.  
  29. The Central Command Unit will automatically:
  30. * Find an antennae on the ship and use it for broadcast
  31. * Find a command seat used for issuing commands called 'RFC_RC' (only renaming required)
  32. * Find and use for target detection any turret with the required customdata tag
  33.  
  34. Bughunting/Problems
  35. --------------------
  36. The code will automatically create a bugreport and save it to the custom-data of the
  37. designated remote block.
  38.  
  39. Suggestions Planned Features
  40. -----------------------------
  41. - Let me know in the workshop page or my discord what you think it needs!
  42.  
  43. ChangeLog:
  44. *Enables antenna
  45. *reversed forward direction on central command module
  46. *Enabled carrier on own grid and related functions
  47.  
  48. */
  49.  
  50. //USER ASSIGNED VARIABLES
  51. string DefaultFormation = ""; //Choose From Line abreast, line astern, drone wall (NOT YET IMPLEMENTED)
  52.  
  53. #endregion
  54.  
  55. #region SETUP
  56. //STORED VARIABLES
  57. //----------------------------------------------------------------------------------------------------------------------
  58.  
  59. //SUBCATEGORY PERMANENT ASSIGNMENTS:
  60. string VERSION = "Ver_006"; //Script Current Version
  61. Dictionary<string, double> SPACINGS = new Dictionary<string, double>() { { "I", 40 }, { "C", 200 }, { "F", 150 }, { "U", -150 } };
  62. Dictionary<string, double> SPACINGS_X = new Dictionary<string, double>() { { "I", 100 }, { "C", 0 }, { "F", 0 }, { "U", -150 } };
  63.  
  64. //SUBCATEGORY STORED BLOCKS
  65. IMyShipController RC;
  66. IMyRadioAntenna RADIO;
  67. List<IMyCameraBlock> CAMERAS = new List<IMyCameraBlock>();
  68. List<IMyLargeTurretBase> DIRECTORS = new List<IMyLargeTurretBase>();
  69.  
  70. //SUBCATEGORY CLASSES
  71. class DRONE_INFO
  72. {
  73. public string ID; //Drone Identifier (contains classification)
  74. public string COMLOC; //Drone Command & locator
  75. public string GLOC; //Generated Locator
  76. public Vector3D LOC; //Current Drone Location
  77. public Vector3D VEL; //Drone Velocity
  78. public Vector3D TVEl; //Target Velocity vector
  79. public string ISDOCKED; //id of docked ship (own Id if not docked)
  80. public double HEALTH; //Health of the ship
  81. public DateTime LAST_PING; //Last recieved ping from the ship
  82. public string EXT_INF; //Drone Extra Info
  83. public string OUTPUT; // String Drone Data Output
  84.  
  85. //Standardised System Of Updating And Saving Drone Data
  86. public static DRONE_INFO DRONE_DATA_RS(string IN_ARG, DRONE_INFO DRONE_INF, bool[] RUN_ID)
  87. {
  88. //Retrieves Data From Store
  89. string[] DRN_INFO = IN_ARG.Split('*');
  90. DRONE_INF.ID = (RUN_ID[0] != true) ? DRONE_INF.ID : DRN_INFO[0];
  91. DRONE_INF.COMLOC = (RUN_ID[1] != true) ? DRONE_INF.COMLOC : DRN_INFO[1];
  92. DRONE_INF.GLOC = (RUN_ID[2] != true) ? DRONE_INF.GLOC : DRN_INFO[2];
  93. if (RUN_ID[3] == true) { Vector3D.TryParse(DRN_INFO[3], out DRONE_INF.LOC); }
  94. if (RUN_ID[4] == true) { Vector3D.TryParse(DRN_INFO[4], out DRONE_INF.VEL); }
  95. if (RUN_ID[5] == true) { Vector3D.TryParse(DRN_INFO[5], out DRONE_INF.TVEl); }
  96. if (RUN_ID[6] == true) { DRONE_INF.ISDOCKED = DRN_INFO[6]; }
  97. if (RUN_ID[7] == true) { DRONE_INF.HEALTH = double.Parse(DRN_INFO[7]); }
  98. if (RUN_ID[8] == true) { DRONE_INF.LAST_PING = DateTime.Parse(DRN_INFO[8]); }
  99. if (RUN_ID[9] == true) { DRONE_INF.EXT_INF = DRN_INFO[9]; }
  100. return DRONE_INF;
  101. }
  102.  
  103. public static DRONE_INFO SAVE(DRONE_INFO DRONE_INF)
  104. {
  105. DRONE_INF.OUTPUT = string.Join("*", "#" + DRONE_INF.ID, DRONE_INF.COMLOC, DRONE_INF.GLOC, DRONE_INF.LOC, DRONE_INF.VEL, DRONE_INF.TVEl, DRONE_INF.ISDOCKED, DRONE_INF.HEALTH, DRONE_INF.LAST_PING, DRONE_INF.EXT_INF, "#" + DRONE_INF.ID);
  106. return DRONE_INF;
  107. }
  108. }
  109. class DOCKPOINT_INFO
  110. {
  111. public string ID; //Dockpoint Identifier (contains docktype classification)
  112. public Vector3D LOC; //Current Dockpoint Location
  113. public string BASE_TAG; //ID of base ship
  114. public string ISDOCKED; //Id of docked ship (own Id if not docked)
  115. public DateTime LAST_PING; //Last recieved ping from the dockpoint
  116. public string OUTPUTROLL; //Coordinates package for drones to interperate
  117. public string OUTPUT; // String Drone Data Output
  118.  
  119. public List<IMyTerminalBlock> ROUTE; //List of route (drone ship only, not updated)
  120.  
  121. //Standardised System Of Updating And Saving Drone Data
  122. public static DOCKPOINT_INFO DOCK_DATA_RS(string IN_ARG, DOCKPOINT_INFO DOCKPT_INF, bool[] RUN_ID)
  123. {
  124. //Retrieves Data From Store
  125. string[] DCK_INFO = IN_ARG.Split('*');
  126. if (RUN_ID[0] == true) { DOCKPT_INF.ID = DCK_INFO[0]; }
  127. if (RUN_ID[1] == true) { Vector3D.TryParse(DCK_INFO[1], out DOCKPT_INF.LOC); }
  128. if (RUN_ID[2] == true) { DOCKPT_INF.BASE_TAG = DCK_INFO[2]; }
  129. if (RUN_ID[3] == true) { DOCKPT_INF.ISDOCKED = DCK_INFO[3]; }
  130. if (RUN_ID[4] == true) { DOCKPT_INF.LAST_PING = DateTime.Parse(DCK_INFO[4]); }
  131. if (RUN_ID[5] == true) { DOCKPT_INF.OUTPUTROLL = DCK_INFO[5]; }
  132.  
  133. DOCKPT_INF.OUTPUT = string.Join("*", "#" + DOCKPT_INF.ID, DOCKPT_INF.LOC, DOCKPT_INF.BASE_TAG, DOCKPT_INF.ISDOCKED, DOCKPT_INF.LAST_PING, DOCKPT_INF.OUTPUTROLL, "#" + DOCKPT_INF.ID);
  134. return DOCKPT_INF;
  135. }
  136.  
  137. //Standardised DockString Saving Procedure
  138. public static DOCKPOINT_INFO SAVE_ROUTE_TO_STRING(DOCKPOINT_INFO DOCKPT_INFO)
  139. {
  140. List<string> OUTPUT = new List<string>();
  141. double OFFSET_CONST = 4;
  142. List<IMyTerminalBlock> DOCKPT_TRAIL = DOCKPT_INFO.ROUTE;
  143.  
  144. //Adds First Ordinates (self and forwards position)
  145. OUTPUT.Add(Vector3D.Round(DOCKPT_TRAIL[0].GetPosition() + DOCKPT_TRAIL[0].WorldMatrix.Forward * (1.5), 2) + "");
  146. OUTPUT.Add(Vector3D.Round(DOCKPT_TRAIL[0].GetPosition() + DOCKPT_TRAIL[0].WorldMatrix.Forward * OFFSET_CONST, 2) + "");
  147.  
  148. //Iterates Through List Of LCD's
  149. for (int i = 1; i < DOCKPT_TRAIL.Count; i++)
  150. { var IMYPLACE = DOCKPT_TRAIL[i]; OUTPUT.Add(Vector3D.Round(IMYPLACE.GetPosition() + IMYPLACE.WorldMatrix.Backward * OFFSET_CONST, 2) + ""); }
  151.  
  152. //Adds Final Position
  153. OUTPUT.Add(Vector3D.Round(DOCKPT_TRAIL[DOCKPT_TRAIL.Count - 1].GetPosition() +
  154. DOCKPT_TRAIL[DOCKPT_TRAIL.Count - 1].WorldMatrix.Backward * OFFSET_CONST + DOCKPT_TRAIL[DOCKPT_TRAIL.Count - 1].WorldMatrix.Up * 100, 2) + "");
  155.  
  156.  
  157. //Saves To String, Updates Locator, (And Updates OUTPUT)
  158. OUTPUT.Reverse();
  159. DOCKPT_INFO.OUTPUTROLL = string.Join("^", OUTPUT);
  160. DOCKPT_INFO.LOC = Vector3D.Round(DOCKPT_TRAIL[0].GetPosition(), 2);
  161. DOCKPT_INFO.OUTPUT = string.Join("*", "#" + DOCKPT_INFO.ID, DOCKPT_INFO.LOC, DOCKPT_INFO.BASE_TAG, DOCKPT_INFO.ISDOCKED, DOCKPT_INFO.LAST_PING, DOCKPT_INFO.OUTPUTROLL, "#" + DOCKPT_INFO.ID);
  162.  
  163. return DOCKPT_INFO;
  164. }
  165.  
  166. public static DOCKPOINT_INFO SAVE(DOCKPOINT_INFO DOCKPT_INFO)
  167. {
  168. DOCKPT_INFO.OUTPUT = string.Join("*", "#" + DOCKPT_INFO.ID, DOCKPT_INFO.LOC, DOCKPT_INFO.BASE_TAG, DOCKPT_INFO.ISDOCKED, DOCKPT_INFO.LAST_PING, DOCKPT_INFO.OUTPUTROLL, "#" + DOCKPT_INFO.ID);
  169. return DOCKPT_INFO;
  170. }
  171.  
  172. }
  173. class DC_INF_INFO
  174. {
  175. public int SIZE; //Size of target
  176. public string TYPE; //Type of target
  177. public Vector3D POSITION; //Position
  178. public string DIRECT_TO_OUTPUT; //Directly Outputted string
  179. public int ST_SIZE; //Start Size
  180. public Vector3D VELOCITY; //Only used For Internal Locks
  181. }
  182. Dictionary<string, DOCKPOINT_INFO> DOCKPOINTS = new Dictionary<string, DOCKPOINT_INFO>();
  183. Dictionary<string, DRONE_INFO> DRONES = new Dictionary<string, DRONE_INFO>();
  184. Dictionary<string, DC_INF_INFO> DECENTIN_INFO = new Dictionary<string, DC_INF_INFO>();
  185. DRONE_INFO MEINFO = new DRONE_INFO(); //Info About Command ship
  186.  
  187. //SUBCATEGORY TEMPORARY ASSIGNMENTS:
  188. bool FIRSTSETUP_HASRUN = false; //Whether Or Not Code has Been Setup
  189. int TIMER_SYSTEM = 0;
  190. Dictionary<string, int> FOLLOW_SPACING = new Dictionary<string, int>(); //
  191.  
  192. //SUBCATEGORY DOCKING SETUP
  193. bool DOCKING_INIT;
  194.  
  195. #endregion
  196.  
  197. //Primary Operators
  198.  
  199. #region MAIN METHOD (unfinished)
  200. /*====================================================================================================================
  201. Function: MAIN METHOD
  202. ---------------------------------------------
  203. function will: Main Method, Timing Calculator And Diagnostics
  204. Performance Cost:
  205. //======================================================================================================================*/
  206. double LAST_RUNTIME;
  207. void Main(string argument)
  208. {
  209. try
  210. {
  211. //System Initialisation
  212. //---------------------------------------
  213. if (FIRSTSETUP_HASRUN == false)
  214. { FIRST_TIME_SETUP(); FIRSTSETUP_HASRUN = true; Echo("System Booting"); return; }
  215.  
  216. if (TIMER_SYSTEM == 0) { LAST_RUNTIME = Runtime.LastRunTimeMs; }
  217. if (argument != "~RFC RUN~" && argument.Contains("#") == false) { return; }
  218. if (TIMER_SYSTEM != 8 && argument.Contains("#") == false)
  219. { TIMER_SYSTEM++; return; }
  220. TIMER_SYSTEM = 0;
  221.  
  222. //Input Handler/Updater
  223. //-------------------------------------------
  224. if (argument != "~RFC RUN~" && argument.Contains("#") == false)
  225. { return; }
  226. INPUT_ORGANISER(argument);
  227. if (argument != "~RFC RUN~")
  228. { return; }
  229.  
  230. //syst diag
  231. OP_BAR();
  232. Echo(VERSION);
  233. Echo(DRONES.Count + " Drones");
  234. Echo(DOCKPOINTS.Count + " Docks");
  235. Echo(DECENTIN_INFO.Count + " DEI'S");
  236. Echo("Runtime: " + Math.Round(LAST_RUNTIME,3));
  237. Echo(VERSION);
  238.  
  239. //Loads CustomData
  240. //---------------------------------
  241. string CUSTDATA = Me.CustomData;
  242. string SQ_DATA = CUSTDATA.Split(new string[] { "##INFO##" }, StringSplitOptions.None)[0]; //0 = sqdata
  243. string[] SQ_DATA_LIST = SQ_DATA.Split(new string[] { "\n" }, StringSplitOptions.None);
  244. foreach (var item in SQ_DATA_LIST)
  245. {
  246. if (item.Split('*').Length < 7 ) { continue; }
  247. if(!DRONES.ContainsKey(item.Split('*')[0].Substring(1, 6))) { continue; }
  248. string DRONE_ID = item.Split('*')[0].Substring(1, 6);
  249. bool[] UPDATE_RUN = new bool[] { false, true, false, false, false, false, false, false, false, true };
  250. DRONES[DRONE_ID] = DRONE_INFO.DRONE_DATA_RS(item, DRONES[DRONE_ID], UPDATE_RUN);
  251. }
  252.  
  253. //Runs For Self Docking
  254. //---------------------------
  255. DOCK_SYST();
  256. DRONES["CA0000"].LAST_PING = DateTime.Now;
  257. MEINFO.LOC = Vector3D.Round(Me.GetPosition(), 2);
  258. MEINFO.VEL = Vector3D.Round(RC.GetShipVelocities().LinearVelocity + (RC.WorldMatrix.Forward * 2));
  259.  
  260. //Scans Sensors For Objects Of Interest (sep method reqd)
  261. //---------------------------------------------------------
  262. var SYST_SENSOR = GridTerminalSystem.GetBlockWithName("RFC_SENSOR") as IMySensorBlock;
  263. List<MyDetectedEntityInfo> DETECTED_ENTITIES = new List<MyDetectedEntityInfo>();
  264. if (SYST_SENSOR != null) //Only runs if able to
  265. {
  266. SYST_SENSOR.DetectedEntities(DETECTED_ENTITIES);
  267. foreach (var item in DETECTED_ENTITIES)
  268. {
  269. if (DECENTIN_INFO.ContainsKey("DEI" + item.EntityId) == false && item.Relationship != MyRelationsBetweenPlayerAndBlock.FactionShare)
  270. {
  271. DC_INF_INFO NEW_ENTITY = new DC_INF_INFO();
  272.  
  273. string ID = "DEI" + item.EntityId;
  274. NEW_ENTITY.SIZE = (int)item.BoundingBox.Size.Length();
  275. NEW_ENTITY.ST_SIZE = (int)item.BoundingBox.Size.Length();
  276. NEW_ENTITY.TYPE = (item.Type == MyDetectedEntityType.Asteroid) ? "AS" : "EN"; //item.Relationship != MyRelationsBetweenPlayerAndBlock.Enemies &&
  277. NEW_ENTITY.POSITION = Vector3D.Round(item.Position, 2);
  278. if ((item.BoundingBox.Size.Length() < 5 || item.Relationship == MyRelationsBetweenPlayerAndBlock.Owner)) { continue; } //halts if not applicable
  279. DECENTIN_INFO.Add(ID, NEW_ENTITY);
  280. DECENTIN_INFO[ID].DIRECT_TO_OUTPUT = "#" + ID + "^" + DECENTIN_INFO[ID].SIZE + "^" + DECENTIN_INFO[ID].TYPE + "^" + DECENTIN_INFO[ID].POSITION;
  281. }
  282. else if (item.Relationship != MyRelationsBetweenPlayerAndBlock.FactionShare)
  283. {
  284. DECENTIN_INFO["DEI" + item.EntityId].SIZE = (int)item.BoundingBox.Size.Length();
  285. //DECENTIN_INFO["DEI" + item.EntityId].TYPE = (item.Type == MyDetectedEntityType.Asteroid) ? "AS" : "EN"; //(item.Relationship != MyRelationsBetweenPlayerAndBlock.Enemies) ? "AS" : "EN";
  286. DECENTIN_INFO["DEI" + item.EntityId].POSITION = Vector3D.Round(item.Position, 2);
  287. DECENTIN_INFO["DEI" + item.EntityId].DIRECT_TO_OUTPUT = "#" + "DEI" + item.EntityId + "^" + DECENTIN_INFO["DEI" + item.EntityId].SIZE + "^" + DECENTIN_INFO["DEI" + item.EntityId].TYPE + "^" + DECENTIN_INFO["DEI" + item.EntityId].POSITION;
  288. }
  289. }
  290. }
  291.  
  292. //Runs DockPoint Logic (maybe once every ten seconds?)
  293. //--------------------------------------------------------
  294. List<string> DOCKKEYS = new List<string>(DOCKPOINTS.Keys);
  295. string DOCKEDIDS = "";
  296. foreach (var item in DRONES)
  297. { if (item.Value.COMLOC.Contains("DOCK")) //preassigns comlocced drones
  298. { DOCKEDIDS = DOCKEDIDS + (item.Value.COMLOC); }}
  299. for (int i = 0; i < DOCKPOINTS.Count; i++)
  300. {
  301. //Echo(((DateTime)DOCKPOINTS[DOCKKEYS[i]].LAST_PING).Ticks + "Dk");
  302. if (DateTime.Now.Ticks - ((DateTime)(DOCKPOINTS[DOCKKEYS[i]]).LAST_PING).Ticks > 50000000)
  303. { DOCKPOINTS.Remove(DOCKKEYS[i]); continue; }
  304. else if (DOCKEDIDS.Contains(DOCKKEYS[i]) == false)
  305. { DOCKPOINTS[DOCKKEYS[i]].ISDOCKED = "free"; }
  306. }
  307.  
  308. //Runs Primary Logic
  309. //------------------------------
  310. FOLLOW_SPACING = new Dictionary<string, int>();
  311. List<string> KEYS = new List<string>(DRONES.Keys);
  312. KEYS.Sort(); //Sorts keys
  313. for (int i = 0; i < DRONES.Count; i++)
  314. {
  315. //Echo(((DateTime)DRONES[KEYS[i]].LAST_PING).Ticks + "");
  316. if (DateTime.Now.Ticks - ((DateTime)(DRONES[KEYS[i]]).LAST_PING).Ticks > 30000000)
  317. { DRONES.Remove(KEYS[i]); continue; }
  318. else
  319. { DRONES[KEYS[i]] = DRONE_RUN(DRONES[KEYS[i]]); }
  320. }
  321.  
  322. //Output Handler
  323. //-------------------------------------------
  324. StringBuilder OUTPUT = new StringBuilder();
  325. OUTPUT.Append("BRDCST");
  326. foreach (var item in DRONES)
  327. { OUTPUT.Append(item.Value.OUTPUT); }
  328. RADIO.TransmitMessage(OUTPUT.ToString(), MyTransmitTarget.Owned);
  329. EN_SCAN_MANAGER();
  330.  
  331. //Saves To Custom Data
  332. //-----------------------
  333. StringBuilder CUSTSAVE = new StringBuilder();
  334. KEYS = new List<string>(DRONES.Keys);
  335. KEYS.Sort(); //sorts keys
  336. for (int i = 0; i < DRONES.Count; i++)
  337. {
  338. DRONES[KEYS[i]] = DRONE_INFO.SAVE(DRONES[KEYS[i]]);
  339. CUSTSAVE.Append(DRONES[KEYS[i]].OUTPUT);
  340. CUSTSAVE.Append("\n");
  341. }
  342. CUSTSAVE.Append("##INFO##\n");
  343. DOCKKEYS = new List<string>(DOCKPOINTS.Keys);
  344. for (int i = 0; i < DOCKPOINTS.Count; i++)
  345. {
  346. DOCKPOINTS[DOCKKEYS[i]] = DOCKPOINT_INFO.SAVE(DOCKPOINTS[DOCKKEYS[i]]);
  347. CUSTSAVE.Append(DOCKPOINTS[DOCKKEYS[i]].OUTPUT);
  348. CUSTSAVE.Append("\n");
  349. }
  350. CUSTSAVE.Append("##INFO##\n");
  351. foreach (var item in DECENTIN_INFO)
  352. {
  353. CUSTSAVE.Append(item.Value.DIRECT_TO_OUTPUT);
  354. CUSTSAVE.Append("\n");
  355. }
  356. Me.CustomData = CUSTSAVE + "";
  357.  
  358. }
  359. catch (Exception e)
  360. { Echo(e + ""); }
  361.  
  362. }
  363. #endregion
  364.  
  365. #region DroneRun
  366. /*=======================================================================================
  367. Function: SQUAD_RUN
  368. ---------------------------------------
  369. function will: Output a string for all military ships
  370. //=======================================================================================*/
  371. DRONE_INFO DRONE_RUN(DRONE_INFO DRONE)
  372. {
  373. try
  374. {
  375. //Error Checks
  376. //-------------------------
  377. if (DRONE.COMLOC == null) //Empty Comlocs
  378. { return DRONE; }
  379. if (DRONE.COMLOC.Split('^').Length > 1) //Comloc not in dictionary
  380. {
  381. //Echo((DRONES.ContainsKey(DRONE.COMLOC.Split('^')[1])) + " drone comloc in library");
  382. if (DRONES.ContainsKey(DRONE.COMLOC.Split('^')[1]) == false && DOCKPOINTS.ContainsKey(DRONE.COMLOC.Split('^')[1]) == false && DRONE.COMLOC.Contains("GOTO") == false && DRONE.COMLOC.Contains("ATTACK") == false && DRONE.COMLOC.Contains("ME") == false)
  383. { return DRONE; }
  384. }
  385.  
  386. //Dock Reader (ensures undocking prior to any further actions)
  387. //-------------------------------------------------------------
  388. string COMM = DRONE.COMLOC.Split('^')[0];
  389. if (DRONE.ISDOCKED != null)
  390. {
  391. //Dock Code Is Stating
  392. if (COMM != "DOCK" && DOCKPOINTS.ContainsKey(DRONE.ISDOCKED))
  393. {
  394. string ID = DRONE.ISDOCKED;
  395. DRONE.GLOC = DOCKPOINTS[ID].OUTPUTROLL;
  396. DRONE.TVEl = new Vector3D(0, 0, 0);
  397. DRONE.COMLOC = "UNDOCK^" + ID;
  398. DOCKPOINTS[ID].ISDOCKED = "UD";
  399.  
  400. Echo((DOCKPOINTS[ID].LOC - DRONE.LOC).Length() + " dist");
  401. if ((DOCKPOINTS[ID].LOC - DRONE.LOC).Length() > 70)
  402. { DRONE.ISDOCKED = DRONE.ID; DOCKPOINTS[ID].ISDOCKED = "free"; DRONE.COMLOC = ""; }
  403.  
  404. return DRONE;
  405. }
  406. }
  407.  
  408. //Command Is Dock
  409. //------------------
  410. if (DRONE.COMLOC.Contains("DOCK"))
  411. {
  412. //Mating Point Setup
  413. //-------------------------------------------------
  414. string LOC_ID = DRONE.COMLOC.Split('^')[1];
  415.  
  416. //First Time Dockpoint Assigner
  417. //--------------------------------------------
  418. if (DRONES.ContainsKey(LOC_ID))
  419. {
  420. //Creates List Of Free Dockpoints On Selected Ship
  421. List<DOCKPOINT_INFO> TEMP_DOCKS = new List<DOCKPOINT_INFO>();
  422. foreach (var item in DOCKPOINTS)
  423. {
  424. if (item.Value.ISDOCKED == "free" && item.Value.BASE_TAG == LOC_ID)
  425. {TEMP_DOCKS.Add(item.Value); }
  426. }
  427.  
  428. //Allocates First One
  429. if (TEMP_DOCKS.Count > 0)
  430. { DRONE.COMLOC = "DOCK^" + TEMP_DOCKS[0].ID; DOCKPOINTS[TEMP_DOCKS[0].ID].ISDOCKED = "NC";}
  431. else
  432. { DRONE.COMLOC = "FOLLOW^" + LOC_ID; return DRONE; } //follow handled on next sequential cycle (eg this only reassigns, next cycle reevaluates this)
  433. }
  434.  
  435. //Sets Mating Dockpoint And Sets Outputroll
  436. //--------------------------------------------
  437. else if (DOCKPOINTS.ContainsKey(LOC_ID))
  438. {
  439. DOCKPOINTS[LOC_ID].ISDOCKED = "NC";
  440. DRONE.ISDOCKED = LOC_ID;
  441. DRONE.GLOC = DOCKPOINTS[LOC_ID].OUTPUTROLL;
  442. DRONE.TVEl = new Vector3D(0, 0, 0);
  443. }
  444. return DRONE;
  445. }
  446.  
  447. //Command Is Follow
  448. //--------------------
  449. if (DRONE.COMLOC.Contains("FOLLOW"))
  450. {
  451. //Find Following Squad positional Data
  452. string LOC = DRONE.COMLOC.Split('^')[1];
  453. if (FOLLOW_SPACING.ContainsKey(LOC) == false)
  454. { FOLLOW_SPACING.Add(LOC, 2); }
  455. else { FOLLOW_SPACING[LOC]++; }
  456. int DIFFER = FOLLOW_SPACING[LOC];
  457.  
  458. //Generates Target Position
  459. Vector3D LEFT_VECT = Vector3D.Normalize(RC.WorldMatrix.Left * 10); //+ DRONES[LOC].VEL (for more precice coordinates)
  460. Vector3D UP_VECT = RC.WorldMatrix.Up;
  461. Vector3D TARGPOS = DRONES.ContainsKey(LOC) ? DRONES[LOC].LOC : RC.GetPosition();
  462. Vector3D TARGVEL = DRONES.ContainsKey(LOC) ? DRONES[LOC].VEL : RC.GetShipVelocities().LinearVelocity + (RC.WorldMatrix.Backward*0.01);
  463.  
  464. Vector3D ADD_VERTICAL = (LOC.Contains("I")) ? new Vector3D() : SPACINGS_X[DRONE.ID.Substring(0, 1)] * UP_VECT; //only y coord if not I-class
  465. Vector3D ADD_ON_POS = (Math.Pow(-1, DIFFER) == -1) ? TARGPOS + SPACINGS[DRONE.ID.Substring(0, 1)] * (DIFFER - 1) * -1 * LEFT_VECT + ADD_VERTICAL : TARGPOS + SPACINGS[DRONE.ID.Substring(0, 1)] * DIFFER * LEFT_VECT + ADD_VERTICAL; //staggers centreline * Math.Pow(-1,DIFFER)
  466.  
  467. //Saves Data
  468. DRONE.GLOC = ADD_ON_POS + "";
  469. DRONE.TVEl = TARGVEL;
  470. }
  471.  
  472. //Command Is Attack
  473. //-------------------
  474. if (DRONE.COMLOC.Contains("ATTACK")) //Attack Tagged Onto End
  475. {
  476. //Splits Command
  477. //Vector3D OUTTER = new Vector3D();
  478. //Vector3D.TryParse(DRONE.COMLOC.Split('^')[1], out OUTTER);
  479.  
  480. //Retrieves DEI From List;
  481. if (DECENTIN_INFO.ContainsKey(DRONE.COMLOC.Split('^')[1]))
  482. {
  483. DRONE.GLOC = DECENTIN_INFO[DRONE.COMLOC.Split('^')[1]].POSITION + "";
  484. DRONE.TVEl = DECENTIN_INFO[DRONE.COMLOC.Split('^')[1]].VELOCITY;
  485. }
  486. else
  487. {
  488. DRONE.COMLOC = "GOTO^" + DRONE.GLOC; //Last detected position
  489. DRONE.TVEl = new Vector3D(0, 0, 0);
  490. }
  491.  
  492.  
  493. ////Finds DEI That's Closest To Command (if within 1000m of target location)
  494. //double DIST = 1000;
  495. //DC_INF_INFO ID_EN = new DC_INF_INFO();
  496. //foreach (var item in DECENTIN_INFO)
  497. //{
  498. // //Retrieves values For Important comparators;
  499. // Vector3D GLOC_PROCES = item.Value.POSITION; // Vector3D.TryParse(, out GLOC_PROCES);
  500. // double DIST_TT = (GLOC_PROCES - OUTTER).Length();
  501. // bool IS_EN = item.Value.DIRECT_TO_OUTPUT.Contains("EN");
  502. // if (IS_EN && DIST_TT < DIST) { ID_EN = item.Value; DIST = DIST_TT; }
  503. //}
  504.  
  505. ////If Target Detected Or Not Near Detected Location Sets To Attack, Otherwise goto a normal command & Clear Attack
  506. //if (ID_EN.DIRECT_TO_OUTPUT != null && ID_EN.POSITION!= new Vector3D())
  507. //{
  508. // DRONE.COMLOC = "ATTACK^" + ID_EN.POSITION; //Reassigns goto to ensure chase
  509. // DRONE.GLOC = ID_EN.POSITION + "";
  510. // DRONE.TVEl = new Vector3D(0, 0, 0);
  511. //}
  512. //else //Distance Larger Than 100m do not redesignate if ((DRONE.LOC - OUTTER).Length() > 100)
  513. //{
  514. // DRONE.GLOC = OUTTER + "";
  515. // DRONE.TVEl = new Vector3D(0, 0, 0);
  516. //}
  517. //else
  518. //{
  519. // DRONE.COMLOC = "GOTO^" + OUTTER; //Last detected position
  520. // DRONE.GLOC = OUTTER + "";
  521. // DRONE.TVEl = new Vector3D(0, 0, 0);
  522. //}
  523.  
  524. }
  525.  
  526. //Command Is GoTo
  527. //------------------
  528. if (DRONE.COMLOC.Contains("GOTO"))
  529. {
  530.  
  531. //Splits Command
  532. Vector3D OUTTER = new Vector3D();
  533. Vector3D.TryParse(DRONE.COMLOC.Split('^')[1], out OUTTER);
  534.  
  535. //Saves Data
  536. DRONE.GLOC = OUTTER + "";
  537. DRONE.TVEl = new Vector3D(0, 0, 0);
  538.  
  539. }
  540.  
  541. //Sets Attack Based Logic Systems (Outdated Code)
  542. //------------------------------------------------------
  543. //double DIST = 999999999;
  544. //DC_INF_INFO ID_EN = new DC_INF_INFO();
  545. //foreach (var item in DECENTIN_INFO)
  546. //{
  547. // //Retrieves values For Important comparators;
  548. // Vector3D GLOC_PROCES; Vector3D.TryParse(DRONE.GLOC, out GLOC_PROCES);
  549. // double DIST_TT = (GLOC_PROCES - item.Value.POSITION).Length();
  550. // bool IS_EN = item.Value.DIRECT_TO_OUTPUT.Contains("EN");
  551. // if (IS_EN && DIST_TT < 1000 && DIST_TT < DIST) { ID_EN = item.Value; DIST = DIST_TT; }
  552. //}
  553. //if (ID_EN.DIRECT_TO_OUTPUT != null)
  554. //{
  555. // //Checks For Agrro And Assigns
  556. // if (ID_EN.DIRECT_TO_OUTPUT.Contains("EN") && DRONE.ID.Contains("CA") == false && DRONE.ID.Contains("CR") == false)
  557. // {
  558. // Echo("reassigning to attack");
  559. // DRONE.GLOC = ID_EN.POSITION + "";
  560. // DRONE.TVEl = new Vector3D(0, 0, 0);
  561.  
  562. // if (DRONE.COMLOC == "")
  563. // { DRONE.COMLOC = "GOTO^" + ID_EN.POSITION; }
  564. // }
  565. //}
  566.  
  567.  
  568.  
  569. }
  570. catch (Exception e) { Echo(DRONE.ID + " ERROR IN " ); RC.CustomData = e+""; }
  571. return DRONE;
  572. }
  573. #endregion
  574.  
  575. #region First Time Setup #RFC#
  576. /*====================================================================================================================
  577. Function: FIRST_TIME_SETUP
  578. ---------------------------------------
  579. function will: Initiates Systems and initiasing Readouts to LCD
  580. Performance Cost:
  581. //======================================================================================================================*/
  582. void FIRST_TIME_SETUP()
  583. {
  584. //Gathers Key Components
  585. //-----------------------------------
  586.  
  587. //Gathers Remote Control
  588. try
  589. {
  590. List<IMyTerminalBlock> TEMP_RC = new List<IMyTerminalBlock>();
  591. GridTerminalSystem.GetBlocksOfType<IMyShipController>(TEMP_RC, b => b.CubeGrid == Me.CubeGrid && b.CustomName == "RFC_RC");
  592. RC = TEMP_RC[0] as IMyShipController;
  593. }
  594. catch { }
  595.  
  596. //Gathers Antennae
  597. try
  598. {
  599. List<IMyTerminalBlock> TEMP = new List<IMyTerminalBlock>();
  600. GridTerminalSystem.GetBlocksOfType<IMyRadioAntenna>(TEMP, b => (b.CubeGrid == Me.CubeGrid && b.CustomData.Contains("RFC_ANT")));
  601. RADIO = TEMP[0] as IMyRadioAntenna;
  602. RADIO.SetValue<long>("PBList", Me.EntityId);
  603. RADIO.Enabled = true;
  604. }
  605. catch { }
  606.  
  607. //Gathers Cameras
  608. try
  609. {
  610. GridTerminalSystem.GetBlocksOfType<IMyCameraBlock>(CAMERAS); //, b => b.CubeGrid == Me.CubeGrid
  611. foreach (var item in CAMERAS)
  612. { (item as IMyCameraBlock).EnableRaycast = true; }
  613. }
  614. catch { }
  615.  
  616. //Gathers Directors
  617. try
  618. {
  619. GridTerminalSystem.GetBlocksOfType<IMyLargeTurretBase>(DIRECTORS, b => b.CustomData == "DIRECTOR" && b.CubeGrid == Me.CubeGrid);
  620. }
  621. catch { }
  622.  
  623. //Initialises Self Ship
  624. MEINFO = new DRONE_INFO();
  625. MEINFO.ID = "CA0000";
  626. MEINFO.COMLOC = "++++";
  627. MEINFO.LOC = Vector3D.Round(Me.GetPosition(), 2);
  628. MEINFO.GLOC = "++++";
  629. MEINFO.ISDOCKED = "false";
  630. MEINFO.TVEl = new Vector3D();
  631. MEINFO.VEL = Vector3D.Round(RC.GetShipVelocities().LinearVelocity + (RC.WorldMatrix.Forward * 2));
  632. MEINFO.HEALTH = 0.9;
  633. MEINFO.LAST_PING = DateTime.Now;
  634. DRONE_INFO.SAVE(MEINFO);
  635. DRONES.Add(MEINFO.ID, MEINFO);
  636.  
  637. //Initialises Self And Docking Routes
  638. if (DOCKING_INIT == false)
  639. { DOCK_INIT(); DOCKING_INIT = true; }
  640.  
  641. //Creates From Permanent Storage
  642. //--------------------------------
  643. string CUSTDATA = Me.CustomData;
  644. string SQ_DATA = CUSTDATA.Split(new string[] { "##INFO##" }, StringSplitOptions.None)[0]; //0 = sqdata
  645. string[] SQ_DATA_LIST = SQ_DATA.Split(new string[] { "\n" }, StringSplitOptions.None);
  646. string DK_DATA = CUSTDATA.Split(new string[] { "##INFO##" }, StringSplitOptions.None)[1]; //0 = sqdata
  647. string[] DK_DATA_LIST = DK_DATA.Split(new string[] { "\n" }, StringSplitOptions.None);
  648.  
  649. foreach (var item in SQ_DATA_LIST)
  650. {
  651. if (item.Split('*').Length < 7) { continue; }
  652. string DRONE_ID = item.Split('*')[0].Substring(1, 6);
  653. if (DRONE_ID.Length<4 || DRONE_ID == "CA0000") { continue; }
  654. DRONE_INFO NEW_DRONE = new DRONE_INFO();
  655. bool[] UPDATE_RUN = new bool[] { false, true, false, false, false, false, false, false, false, false };
  656. NEW_DRONE = DRONE_INFO.DRONE_DATA_RS(item, NEW_DRONE, UPDATE_RUN);
  657. NEW_DRONE.LAST_PING = DateTime.Now;
  658. NEW_DRONE.ID = DRONE_ID;
  659. DRONES.Add(DRONE_ID, NEW_DRONE);
  660. Echo("Sucessfully Added New Drone " + DRONES.Count + " " + DRONE_ID);
  661. }
  662.  
  663. foreach (var item in DK_DATA_LIST)
  664. {
  665. if (item.Split('*').Length < 4) { continue; }
  666. string ID = item.Split('*')[0].Substring(1, 6);
  667. if (ID.Length < 4 || DOCKPOINTS.ContainsKey(ID)) { continue; }
  668. DOCKPOINT_INFO NEW_DRONE = new DOCKPOINT_INFO();
  669. bool[] UPDATE_RUN = new bool[] { true, true, true, true, true, true};
  670. NEW_DRONE = DOCKPOINT_INFO.DOCK_DATA_RS(item, NEW_DRONE, UPDATE_RUN);
  671. NEW_DRONE.LAST_PING = DateTime.Now;
  672. NEW_DRONE.ID = ID;
  673. DOCKPOINTS.Add(ID, NEW_DRONE);
  674. Echo("Sucessfully Added New Dockpoint " + DRONES.Count + " " + ID);
  675. }
  676.  
  677. }
  678. //----------==--------=------------=-----------=---------------=------------=-------==--------=------------=-----------=----------
  679. #endregion
  680.  
  681. #region RFC Function bar #RFC#
  682. /*=================================================
  683. Function: RFC Function bar #RFC#
  684. --------------------------------------- */
  685. string[] FUNCTION_BAR = new string[] { "", " ===||===", " ==|==|==", " =|====|=", " |======|", " ======" };
  686. int FUNCTION_TIMER = 0; //For Runtime Indicator
  687. void OP_BAR()
  688. {
  689. FUNCTION_TIMER++;
  690. Echo(" ~ MKII RFC AI Running~ \n " + FUNCTION_BAR[FUNCTION_TIMER] + "");
  691. if (FUNCTION_TIMER == 5) { FUNCTION_TIMER = 0; }
  692. }
  693. #endregion
  694.  
  695. #region Input Organiser
  696. /*=======================================================================================
  697. Function: INPUT_ORGANISER
  698. ---------------------------------------
  699. function will: Save or update newly Found Drones Or Docking Points
  700. //=======================================================================================*/
  701. void INPUT_ORGANISER(string argument)
  702. {
  703. string[] InputData = argument.Split('#');
  704. foreach (var item in InputData)
  705. {
  706. string ID = item.Split('*')[0]; //Item ID
  707.  
  708. //Case, (Standard Drones)
  709. //------------------------------------------------
  710. if (ID.Contains("DK") == false && ID.Contains("DEI") == false)
  711. {
  712. if (DRONES.ContainsKey(ID) == false && item.Split('*').Length > 8)
  713. {
  714. DRONE_INFO NEW_DRONE = new DRONE_INFO();
  715. bool[] FC_CENTRAL_RUN = new bool[] { true, true, false, true, true, true, true, true, true, false };
  716. NEW_DRONE = DRONE_INFO.DRONE_DATA_RS(item, NEW_DRONE, FC_CENTRAL_RUN);
  717. NEW_DRONE.GLOC = NEW_DRONE.LOC + "";
  718. if (DOCKPOINTS.ContainsKey(NEW_DRONE.ISDOCKED)) //Function To ensure if it appears already docked allows it to initiaslise docked
  719. { NEW_DRONE.GLOC = "DOCK^" + NEW_DRONE.ISDOCKED; }
  720. DRONES.Add(ID, NEW_DRONE);
  721. Echo("Sucessfully Added New Drone " + DRONES.Count + "");
  722. }
  723. else if (item.Split('*').Length > 8)
  724. {
  725. bool[] FC_CENTRAL_RUN = new bool[] { false, false, false, true, true, true, false, true, true, false };
  726. DRONES[ID] = DRONE_INFO.DRONE_DATA_RS(item, DRONES[ID], FC_CENTRAL_RUN);
  727. }
  728. }
  729.  
  730. //Case, Dockpooints
  731. //---------------------------------------------
  732. else if (ID.Contains("DK") == true)
  733. {
  734. if (DOCKPOINTS.ContainsKey(ID) == false && item.Split('*').Length > 4)
  735. {
  736. DOCKPOINT_INFO NEW_DOCKPT = new DOCKPOINT_INFO();
  737. bool[] DOCKPOINT_INPUT = new bool[] { true, true, true, false, true, true };
  738. NEW_DOCKPT = DOCKPOINT_INFO.DOCK_DATA_RS(item, NEW_DOCKPT, DOCKPOINT_INPUT);
  739. DOCKPOINTS.Add(ID, NEW_DOCKPT);
  740. Echo("Sucessfully Added New Dockpoint " + DRONES.Count + "");
  741. }
  742. else if (item.Split('*').Length > 4)
  743. {
  744. bool[] DOCKPOINT_INPUT = new bool[] { false, true, false, false, true, true };
  745. DOCKPOINTS[ID] = DOCKPOINT_INFO.DOCK_DATA_RS(item, DOCKPOINTS[ID], DOCKPOINT_INPUT);
  746. }
  747. }
  748.  
  749. //Case, Is a DEI
  750. //--------------------------
  751. else if (ID.Contains("DEI") == true)
  752. {
  753. ID = item.Split('^')[0]; //Item ID
  754. if (DECENTIN_INFO.ContainsKey(ID) == false && item.Split('^').Length > 3)
  755. {
  756. DC_INF_INFO NEW_DEI = new DC_INF_INFO();
  757. NEW_DEI.DIRECT_TO_OUTPUT = "#" + item;
  758. NEW_DEI.TYPE = "EN";
  759. Vector3D TRIAL_POS_AS; Vector3D.TryParse(item.Split('^')[3], out TRIAL_POS_AS);
  760. NEW_DEI.POSITION = TRIAL_POS_AS;
  761. DECENTIN_INFO.Add(ID, NEW_DEI);
  762. //Echo("Sucessfully Added New DEI" + DRONES.Count + "");
  763. }
  764. else if (item.Split('^').Length > 3)
  765. {
  766. Vector3D TRIAL_POS_AS; Vector3D.TryParse(item.Split('^')[3], out TRIAL_POS_AS);
  767. DECENTIN_INFO[ID].POSITION = TRIAL_POS_AS;
  768. DECENTIN_INFO[ID].DIRECT_TO_OUTPUT = "#"+ item;
  769. }
  770. }
  771. }
  772. }
  773. #endregion
  774.  
  775. #region SCAN
  776. /*====================================================================================================================================
  777. Secondary Function: SCAN_MANAGER
  778. -----------------------------------------------------
  779. Function will: Given two inputs manage vector-based thrusting
  780. Outputs: Position for shot convergence, if there is a target in the way, if that target is friendly, information reagrding locked ship
  781. //-=--------------=-----------=-----------=-------------------=-------------------=----------------------=----------------------------*/
  782. void EN_SCAN_MANAGER()
  783. {
  784. //Initialises Temporary Camera List
  785. //-------------------------------------
  786. List<IMyCameraBlock> TEMP_CAMERAS = new List<IMyCameraBlock>();
  787. TEMP_CAMERAS.AddList(CAMERAS);
  788.  
  789. //Runs through For Each DEI, If Enemy Initialise Tracking
  790. //---------------------------------------------------------
  791. foreach (var item in DECENTIN_INFO)
  792. {
  793.  
  794. //Only Enemy Ships
  795. //----------------------------
  796. if (item.Value.TYPE != "EN")
  797. { continue; }
  798.  
  799. //Initialises DEI
  800. //-------------------
  801. MyDetectedEntityInfo TEMP_INFO = new MyDetectedEntityInfo();
  802. var SCAN_LOCKED_SHIP = item.Value;
  803.  
  804. //Runs Locked System Scan
  805. //-------------------------
  806. Vector3D TESTPOS = SCAN_LOCKED_SHIP.POSITION + (SCAN_LOCKED_SHIP.VELOCITY) * 0.13333333 * 1; //Runtime.TimeSinceLastRun.Milliseconds/1000
  807. Vector3D DIRECTION = Vector3D.Normalize(TESTPOS - RC.GetPosition());
  808. double DISTANCE = (TESTPOS - RC.GetPosition()).Length() + 40;
  809. Vector3D POS = DIRECTION * DISTANCE + RC.GetPosition();
  810. foreach (var ITEM in TEMP_CAMERAS)
  811. {
  812. IMyCameraBlock CAMERA = (ITEM as IMyCameraBlock);
  813. if (CAMERA.CanScan(POS) && CAMERA.IsWorking && CAMERA.AvailableScanRange > ((POS-CAMERA.GetPosition()).Length()+40))
  814. {
  815. //Echo(CAMERA.CustomName);
  816. TEMP_CAMERAS.Remove(ITEM);
  817. TEMP_INFO = CAMERA.Raycast(POS);
  818. break;
  819. }
  820. }
  821.  
  822. //Detects enemy entity info and outputs
  823. //Echo((!TEMP_INFO.IsEmpty()) +""+ (TEMP_INFO.Relationship == MyRelationsBetweenPlayerAndBlock.Enemies) + "");
  824. if (!TEMP_INFO.IsEmpty() && TEMP_INFO.Relationship == MyRelationsBetweenPlayerAndBlock.Enemies)
  825. {
  826. item.Value.POSITION = TEMP_INFO.Position;
  827. item.Value.SIZE = (int)(TEMP_INFO.BoundingBox.Max - TEMP_INFO.BoundingBox.Min).Length();
  828. item.Value.VELOCITY = TEMP_INFO.Velocity;
  829. }
  830. else
  831. {
  832. if ((DateTime.Now.Second + "").Contains("7"))
  833. { DECENTIN_INFO.Remove(item.Key); }
  834. }
  835. }
  836.  
  837.  
  838.  
  839. //Runs Through Each Opoerational Turret, Adds Anything Detected to list
  840. //----------------------------------------------------------------------
  841. foreach (var item in DIRECTORS)
  842. {
  843. if (item.IsUnderControl)
  844. {
  845. //Initialises Scan
  846. var DIRECTOR = item;
  847. #region Turret Vector Snippet
  848. //GETTING TURRET VECTOR //If tracking identify direction and position
  849. float AZ = DIRECTOR.Azimuth;
  850. float EL = DIRECTOR.Elevation;
  851. Vector3 TURRETVECTOR = new Vector3(0, 0, 0);
  852. Vector3.CreateFromAzimuthAndElevation(AZ, EL, out TURRETVECTOR);
  853. //-----------------------------------------------------------------------------------------
  854. Vector3D ORIGINPOS = DIRECTOR.GetPosition();
  855. //----------------------------------------
  856. //Get forward unit vector
  857. var FORWARDPOS = DIRECTOR.Position + Base6Directions.GetIntVector(DIRECTOR.Orientation.TransformDirection(Base6Directions.Direction.Forward));
  858. var FORWARD = DIRECTOR.CubeGrid.GridIntegerToWorld(FORWARDPOS);
  859. var FORWARDVECTOR = Vector3D.Normalize(FORWARD - ORIGINPOS);
  860. //----------------------------------------
  861. //Get Up unit vector
  862. var UPPOS = DIRECTOR.Position + Base6Directions.GetIntVector(DIRECTOR.Orientation.TransformDirection(Base6Directions.Direction.Up));
  863. var UP = DIRECTOR.CubeGrid.GridIntegerToWorld(UPPOS);
  864. var UPVECTOR = Vector3D.Normalize(UP - ORIGINPOS);
  865. //----------------------------------------
  866. Quaternion QUAT_ONE = Quaternion.CreateFromForwardUp(FORWARDVECTOR, UPVECTOR);
  867. //----------------------------------------
  868. //APPLYING QUAT TO A
  869. Vector3D TARGETPOS1 = Vector3D.Transform(TURRETVECTOR, QUAT_ONE);
  870. #endregion
  871. MyDetectedEntityInfo TEMP_INFO = new MyDetectedEntityInfo();
  872.  
  873. //Runs Through Each Camera
  874. foreach (var ITEM in TEMP_CAMERAS)
  875. {
  876. IMyCameraBlock CAMERA = (ITEM as IMyCameraBlock);
  877. if (CAMERA.CanScan(TARGETPOS1 * 10000 + DIRECTOR.GetPosition()))
  878. {
  879. TEMP_CAMERAS.Remove(ITEM);
  880. TEMP_INFO = CAMERA.Raycast(TARGETPOS1 * 10000 + DIRECTOR.GetPosition());
  881. break;
  882. }
  883. }
  884.  
  885. //Adds DEI If not already Added
  886. if (!TEMP_INFO.IsEmpty() && TEMP_INFO.Relationship != MyRelationsBetweenPlayerAndBlock.Owner)
  887. {
  888. if (DECENTIN_INFO.ContainsKey("DEI"+TEMP_INFO.EntityId) == false)
  889. {
  890. DC_INF_INFO NEW_DEI = new DC_INF_INFO();
  891. NEW_DEI.DIRECT_TO_OUTPUT = "#" + "DEI" + TEMP_INFO.EntityId + "^" + 20 + "^" + "EN" + "^" + Vector3D.Round(TEMP_INFO.Position, 2);
  892. NEW_DEI.TYPE = "EN";
  893. NEW_DEI.POSITION = TEMP_INFO.Position;
  894. NEW_DEI.VELOCITY = TEMP_INFO.Velocity;
  895. DECENTIN_INFO.Add("DEI" + TEMP_INFO.EntityId, NEW_DEI);
  896. //Echo("Sucessfully Added New DEI" + DRONES.Count + "");
  897. }
  898. }
  899. }
  900. }
  901. }
  902. //----------==--------=------------=-----------=---------------=------------=-------==--------=------------=-----------=----------
  903.  
  904. #endregion
  905.  
  906. //Docking Systems
  907.  
  908. #region DOCK_SYSTEM CENCOM
  909. /*====================================================================================================================================
  910. Secondary Function: DOCK_SYSTEM
  911. -----------------------------------------------------
  912. Function will: Operate docking & undocking route setup and outputs
  913. //-=--------------=-----------=-----------=-------------------=-------------------=----------------------=----------------------------*/
  914. string DOCK_SYST()
  915. {
  916.  
  917. //Generates System Dock Outputs
  918. StringBuilder DOCKOUTPUT = new StringBuilder();
  919. List<string> KEYS = new List<string>(DOCKPOINTS.Keys);
  920. for (int i = 0; i < DOCKPOINTS.Count; i++)
  921. {
  922. //Only For dockpoints on this ship
  923. if (DOCKPOINTS[DOCKPOINTS[KEYS[i]].ID].BASE_TAG.Contains("CA0000") == false || DOCKPOINTS[DOCKPOINTS[KEYS[i]].ID].ROUTE == null)
  924. { continue; }
  925.  
  926. //Updates Docking Location
  927. DOCKPOINTS[DOCKPOINTS[KEYS[i]].ID].LAST_PING = DateTime.Now;
  928. DOCKPOINTS[DOCKPOINTS[KEYS[i]].ID] = DOCKPOINT_INFO.SAVE_ROUTE_TO_STRING(DOCKPOINTS[KEYS[i]]);
  929.  
  930. //Appends Location To String
  931. DOCKOUTPUT.Append(DOCKPOINTS[KEYS[i]].OUTPUT);
  932. }
  933. return DOCKOUTPUT + "";
  934. }
  935. #endregion
  936.  
  937. #region Connector Trail Setup
  938. /*=======================================================================================
  939. Function: Connector Trail Setup
  940. ---------------------------------------
  941. Function will: Setup A Connector-LCD Trail
  942. //=======================================================================================*/
  943. List<IMyTerminalBlock> TRAIL_SETUP(IMyShipConnector CONN)
  944. {
  945.  
  946. //Sets Up Temporary
  947. List<IMyTerminalBlock> TEMP_D = new List<IMyTerminalBlock>();
  948. List<IMyTerminalBlock> ROUTE_BLOCKS = new List<IMyTerminalBlock>();
  949.  
  950. //Retrieves And Stores First Text Panel
  951. GridTerminalSystem.GetBlocksOfType<IMyTextPanel>(TEMP_D, block => (block.CubeGrid == Me.CubeGrid));
  952. if (TEMP_D.Count == 0) { return ROUTE_BLOCKS; }
  953. var INITIAL_LCD = default(IMyTextPanel);
  954. double DIST = 5;
  955. foreach (var item in TEMP_D)
  956. {
  957. var ME_DIST = (item.GetPosition() - CONN.GetPosition()).Length();
  958. if (ME_DIST < DIST)
  959. { INITIAL_LCD = item as IMyTextPanel; DIST = ME_DIST; }
  960. }
  961.  
  962. //Logic Check To Ensure No Enpty Routes Are Output
  963. if (INITIAL_LCD == null) { Echo("Non Route Detected"); return new List<IMyTerminalBlock>(); }
  964. ROUTE_BLOCKS.Add(CONN);
  965. ROUTE_BLOCKS.Add(INITIAL_LCD);
  966.  
  967. //Iterates Through Panels Until Path Is Open
  968. for (int i = 1; i < 7; i++)
  969. {
  970. List<IMyTerminalBlock> TEMP_E = new List<IMyTerminalBlock>();
  971. GridTerminalSystem.GetBlocksOfType<IMyTextPanel>(TEMP_E, block => Vector3D.Dot(ROUTE_BLOCKS[i].WorldMatrix.Up, Vector3D.Normalize(block.GetPosition() - ROUTE_BLOCKS[i].GetPosition())) > 0.999);
  972. if (TEMP_E.Count == 0) { break; } //ends if nothing above
  973. IMyTextPanel TEMP_PANEL = default(IMyTextPanel);
  974. DIST = 300;
  975. foreach (var item in TEMP_E)
  976. {
  977. var ME_DIST = (item.GetPosition() - CONN.GetPosition()).Length();
  978. if (ME_DIST < DIST)
  979. { TEMP_PANEL = item as IMyTextPanel; DIST = ME_DIST; }
  980. }
  981. ROUTE_BLOCKS.Add(TEMP_PANEL);
  982. }
  983.  
  984. //Outputs Panels And Connector
  985. Echo("Iteration Through Panels Complete");
  986. return ROUTE_BLOCKS;
  987. }
  988. #endregion
  989.  
  990. #region Dock Initialisation
  991. /*=======================================================================================
  992. Function: DOCK INIT
  993. ---------------------------------------
  994. function will: Initialise the docking manager
  995. //=======================================================================================*/
  996. void DOCK_INIT()
  997. {
  998. //Runs Through All Docking Routes, Forms New Docking routes as terminal block lists
  999. List<IMyTerminalBlock> TEMP = new List<IMyTerminalBlock>();
  1000. GridTerminalSystem.GetBlocksOfType<IMyShipConnector>(TEMP, b => b.CubeGrid == Me.CubeGrid);
  1001. foreach (IMyTerminalBlock TERMINAL_CONNECTOR in TEMP)
  1002. {
  1003. Echo("started loop");
  1004. List<IMyTerminalBlock> TRAIL_LIST = TRAIL_SETUP(TERMINAL_CONNECTOR as IMyShipConnector);
  1005. Echo("ran coord init");
  1006. if (TRAIL_LIST.Count > 0)
  1007. {
  1008. DOCKPOINT_INFO NEW_DOCKPT = new DOCKPOINT_INFO();
  1009. NEW_DOCKPT.ID = "DK" + TERMINAL_CONNECTOR.EntityId.ToString().Substring(0, 4);
  1010. NEW_DOCKPT.BASE_TAG = MEINFO.ID;
  1011. NEW_DOCKPT.LAST_PING = DateTime.Now;
  1012. NEW_DOCKPT.ROUTE = TRAIL_LIST;
  1013. List<string> ROUTE_POSITIONS = new List<string>();
  1014. foreach (var item in NEW_DOCKPT.ROUTE)
  1015. { ROUTE_POSITIONS.Add(item.GetPosition() + ""); }
  1016. NEW_DOCKPT.OUTPUTROLL = string.Join("^", ROUTE_POSITIONS);
  1017.  
  1018. DOCKPOINTS.Add(NEW_DOCKPT.ID, NEW_DOCKPT);
  1019. }
  1020. }
  1021. }
  1022.  
  1023. #endregion
  1024.  
  1025. // COPY TO HERE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement