Advertisement
Guest User

Skillful R1 Nov 2014 KSP 0.25

a guest
Nov 17th, 2014
1,166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 304.60 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using UnityEngine;
  8.  
  9.  
  10. public class IDDepot : PartModule
  11. {
  12. public bool doItOnce = true;
  13. //762mmAmmo, 30calAmmo, 50calAmmo, 30mmAmmo, 5inchAmmo, 14inchAmmo
  14.  
  15. [KSPField(isPersistant = true, guiActiveEditor = true, guiActive = true, guiName = "AmmoType: ")]
  16. public string setAmmoTo = "762mmAmmo";
  17.  
  18. [KSPField(isPersistant = true, guiActiveEditor = true, guiActive = false, guiName = "AmmoType "), UI_FloatRange(minValue = 1f, maxValue = 2f, stepIncrement = 1f)]
  19. public float setAmmoNumA = 1f;
  20.  
  21. [KSPField(isPersistant = true, guiActiveEditor = true, guiActive = false, guiName = "AmmoType "), UI_FloatRange(minValue = 3f, maxValue = 4f, stepIncrement = 1f)]
  22. public float setAmmoNumB = 3f;
  23.  
  24. [KSPField(isPersistant = true, guiActiveEditor = true, guiActive = false, guiName = "AmmoType "), UI_FloatRange(minValue = 4f, maxValue = 5f, stepIncrement = 1f)]
  25. public float setAmmoNumC = 4f;
  26.  
  27. [KSPField(isPersistant = true, guiActiveEditor = true, guiActive = false, guiName = "AmmoType "), UI_FloatRange(minValue = 6f, maxValue = 6f, stepIncrement = 1f)]
  28. public float setAmmoNumD = 6f;
  29.  
  30. [KSPField(isPersistant = true, guiActiveEditor = true, guiActive = false, guiName = "Fill% "), UI_FloatRange(minValue = 10f, maxValue = 100f, stepIncrement = 10f)]
  31. public float setAmmoTakePer = 100f;
  32.  
  33. [KSPField(isPersistant = true, guiActiveEditor = true, guiActive = true, guiName = "MaxRnds ")]
  34. public float maxRounds = 0f;
  35.  
  36. [KSPField]
  37. public float effectiveSpace = 0.1f;
  38.  
  39. public float volumeOfDepot = 0f; // cm3
  40.  
  41. public float packingOverhead = 1.125f;
  42.  
  43. public float launchSaveTimer = 500f;
  44.  
  45. [KSPField(isPersistant = true)]
  46. public string depotSelection = "";
  47.  
  48. public bool madeChange = false;
  49. public float updateAmmoTimer = 5f;
  50.  
  51. public int roundSetAmmoTo = 0;
  52.  
  53. [KSPField(guiActive = false, isPersistant = true)]
  54. public double idAmmoAmount;
  55.  
  56. [KSPField(guiActive = false, isPersistant = true)]
  57. public double idAmmoMax;
  58.  
  59. public string idAmmoName = "";
  60.  
  61. public float maxOrdLength = 0f;
  62.  
  63. public float ordLength = 0f;
  64. public float ordDia = 0f;
  65.  
  66. public void Start()
  67. {
  68. //PartResourceList rresourceList = this.part.Resources;
  69. //foreach (PartResource rresource in rresourceList)
  70. //{
  71.  
  72. // if (rresource.resourceName != "IDammo")
  73. // {
  74.  
  75. // }
  76. //}
  77.  
  78. if (depotSelection == "A")
  79. {
  80. Fields["setAmmoNumB"].guiActiveEditor = false;
  81. Fields["setAmmoNumC"].guiActiveEditor = false;
  82. Fields["setAmmoNumD"].guiActiveEditor = false;
  83. }
  84. if (depotSelection == "B")
  85. {
  86. Fields["setAmmoNumA"].guiActiveEditor = false;
  87. Fields["setAmmoNumC"].guiActiveEditor = false;
  88. Fields["setAmmoNumD"].guiActiveEditor = false;
  89. }
  90. if (depotSelection == "C")
  91. {
  92. Fields["setAmmoNumA"].guiActiveEditor = false;
  93. Fields["setAmmoNumB"].guiActiveEditor = false;
  94. Fields["setAmmoNumD"].guiActiveEditor = false;
  95. }
  96. if (depotSelection == "D")
  97. {
  98. Fields["setAmmoNumA"].guiActiveEditor = false;
  99. Fields["setAmmoNumB"].guiActiveEditor = false;
  100. Fields["setAmmoNumC"].guiActiveEditor = false;
  101. }
  102.  
  103. Collider thisCol = GetComponentInChildren<Collider>();
  104. if (thisCol != null)
  105. {
  106. //print("Found a collider on the depot!");
  107. volumeOfDepot = (thisCol.bounds.extents.x * 100f) * (thisCol.bounds.extents.y * 100f) * (thisCol.bounds.extents.z * 100f);
  108. }
  109. if (volumeOfDepot <= 0f)
  110. {
  111. volumeOfDepot = 40000f;
  112. //print("This depot is " + volumeOfDepot + " cubic cm.");
  113. }
  114.  
  115. if (thisCol.bounds.extents.x > thisCol.bounds.extents.y && thisCol.bounds.extents.x > thisCol.bounds.extents.z)
  116. {
  117. //print("X is the largest dimension");
  118. maxOrdLength = thisCol.bounds.extents.x * 100f;
  119. }
  120. else if (thisCol.bounds.extents.y > thisCol.bounds.extents.z)
  121. {
  122. //print("Y is the largest dimension");
  123. maxOrdLength = thisCol.bounds.extents.y * 100f;
  124. }
  125. else
  126. {
  127. //print("Z is the largest dimension");
  128. maxOrdLength = thisCol.bounds.extents.z * 100f;
  129. }
  130.  
  131. if (effectiveSpace > 1f) effectiveSpace = 1f;
  132. }
  133.  
  134. public void FixedUpdate()
  135. {
  136.  
  137.  
  138.  
  139. //int roundSetAmmoTo = (int)setAmmoNum;
  140. if (HighLogic.LoadedSceneIsEditor)
  141. {
  142. if (depotSelection == "A")
  143. {
  144. roundSetAmmoTo = (int)setAmmoNumA;
  145. }
  146. if (depotSelection == "B")
  147. {
  148. roundSetAmmoTo = (int)setAmmoNumB;
  149. }
  150. if (depotSelection == "C")
  151. {
  152. roundSetAmmoTo = (int)setAmmoNumC;
  153. }
  154. if (depotSelection == "D")
  155. {
  156. roundSetAmmoTo = (int)setAmmoNumD;
  157. }
  158.  
  159. if (roundSetAmmoTo == 1)
  160. {
  161. setAmmoTo = "762mmAmmo";
  162. ordLength = 3.81f; // in cm
  163. ordDia = 0.762f; // in cm
  164. }
  165. if (roundSetAmmoTo == 2)
  166. {
  167. setAmmoTo = "30calAmmo";
  168. ordLength = 3.95f;
  169. ordDia = 0.762f;
  170. }
  171. if (roundSetAmmoTo == 3)
  172. {
  173. setAmmoTo = "50calAmmo";
  174. ordLength = 6.475f;
  175. ordDia = 1.295f;
  176. }
  177. if (roundSetAmmoTo == 4)
  178. {
  179. setAmmoTo = "30mmAmmo";
  180. ordLength = 15f;
  181. ordDia = 3f;
  182. }
  183. if (roundSetAmmoTo == 5)
  184. {
  185. setAmmoTo = "5inchAmmo";
  186. ordLength = 63.5f;
  187. ordDia = 12.7f;
  188. }
  189. if (roundSetAmmoTo == 6)
  190. {
  191. setAmmoTo = "14inchAmmo";
  192. ordLength = 180f;
  193. ordDia = 36f;
  194. }
  195.  
  196. if (ordLength < maxOrdLength)
  197. {
  198. maxRounds = ((volumeOfDepot * effectiveSpace) / ((ordLength * ordDia) * packingOverhead));
  199.  
  200. }
  201. else if (ordLength > maxOrdLength)
  202. {
  203. maxRounds = 0f;
  204. }
  205.  
  206.  
  207. if (updateAmmoTimer > 0f)
  208. {
  209. updateAmmoTimer--;
  210.  
  211. if (updateAmmoTimer <= 0f)
  212. {
  213. if (madeChange == false)
  214. {
  215. madeChange = true;
  216. }
  217.  
  218. FillTheDepot();
  219.  
  220. updateAmmoTimer = 15f;
  221. }
  222. }
  223. }
  224.  
  225.  
  226.  
  227.  
  228. }
  229.  
  230. public void FillTheDepot()
  231. {
  232. PartResourceList rresourceList = this.part.Resources;
  233. foreach (PartResource rresource in rresourceList)
  234. {
  235. if (rresource.resourceName == setAmmoTo)
  236. {
  237. if (madeChange == true)
  238. {
  239. idAmmoAmount = (double)(maxRounds * (setAmmoTakePer * 0.01f));
  240. idAmmoMax = (double)maxRounds;
  241. idAmmoName = setAmmoTo;
  242. rresource.resourceName = setAmmoTo;
  243. rresource.amount = Math.Round(idAmmoAmount);
  244. rresource.maxAmount = Math.Round(idAmmoMax);
  245. //print("inside the filldepot, number: " + idAmmoAmount + " max: " + idAmmoMax);
  246.  
  247. madeChange = false;
  248. }
  249. }
  250. else
  251. {
  252. rresource.amount = 0.0d;
  253. rresource.maxAmount = 0.0d;
  254. }
  255. }
  256. }
  257.  
  258.  
  259.  
  260. }
  261.  
  262. ************************************************************IDDepot
  263.  
  264. using System;
  265. using System.Collections.Generic;
  266. using System.Threading.Tasks;
  267. using System.IO;
  268. using UnityEngine;
  269.  
  270.  
  271. public class relayIFF : PartModule
  272. {
  273. [KSPField(guiActive = true, isPersistant = true)]
  274. public string setIFF = "";
  275.  
  276. [KSPEvent(active = true, guiName = "Fix Damage", guiActiveUnfocused = true, externalToEVAOnly = true, guiActive = true)]
  277. public void showTripFix()
  278. {
  279. targetPart thisTPart = GetComponent<targetPart>();
  280. if (thisTPart != null)
  281. {
  282. thisTPart.fixState();
  283. }
  284.  
  285. }
  286.  
  287. [KSPEvent(name = "togIFF", active = true, guiActive = true, guiName = "Toggle IFF")]
  288. public void toggleIFF()
  289. {
  290. if (setIFF == "blue")
  291. {
  292. setIFF = "red";
  293.  
  294. }
  295. else if (setIFF == "red")
  296. {
  297. setIFF = "blue";
  298.  
  299. }
  300. }
  301.  
  302.  
  303.  
  304. public void OnDestroy()
  305. {
  306. List<Vessel> pullBlueList = IFFList.Instance.IFFBlue();
  307. pullBlueList.Remove(this.vessel);
  308.  
  309. List<Vessel> pullRedList = IFFList.Instance.IFFRed();
  310. pullBlueList.Remove(this.vessel);
  311.  
  312. print("A vessel was destroyed, and was removed from the IFF list");
  313.  
  314. }
  315.  
  316. }
  317.  
  318. public class saveIDVessel : PartModule
  319. {
  320. public bool saveItNow = false;
  321. public bool doItOnce = false;
  322.  
  323. public bool setTimerOnce = true;
  324.  
  325. public float updateAutoSaveTimer = 900f;
  326.  
  327. public float launchSaveTimer = 600f;
  328. public float launchLoadTimer = 150f;
  329.  
  330. public float lastLoadTime;
  331. public float lastSaveTime;
  332.  
  333. [KSPField(isPersistant = true)]
  334. public float lastSavedPartsCount;
  335.  
  336. public bool partCountChanged = false;
  337.  
  338. public bool saveBypass = false;
  339.  
  340. public bool pauseSave = true;
  341. public bool oneStartLoad = true;
  342.  
  343. public bool loadItNow = false;
  344.  
  345. [KSPField(isPersistant = true)]
  346. public bool IDTargetSaved = false;
  347.  
  348. [KSPField(isPersistant = true)]
  349. public string saveFileName;
  350.  
  351. public float saveTime;
  352.  
  353. public float savePartCPS;
  354.  
  355. public targetPart CPSselect;
  356.  
  357. public List<targetPart> CPSlist;
  358.  
  359. [KSPEvent(active = true, guiName = "Test Filesave", guiActiveUnfocused = true, externalToEVAOnly = false, guiActive = true)]
  360. public void TrySave()
  361. {
  362. saveFileName = this.vessel.vesselName + this.vessel.referenceTransformId + ".txt";
  363. saveItNow = true;
  364. doItOnce = true;
  365. }
  366.  
  367. [KSPEvent(active = true, guiName = "Test Fileload", guiActiveUnfocused = true, externalToEVAOnly = false, guiActive = true)]
  368. public void TryLoad()
  369. {
  370. saveFileName = this.vessel.vesselName + this.vessel.referenceTransformId + ".txt";
  371. loadItNow = true;
  372.  
  373. }
  374.  
  375.  
  376. public void FixedUpdate()
  377. {
  378. if (HighLogic.LoadedSceneIsFlight)
  379. {
  380. if (this.vessel.situation == Vessel.Situations.DOCKED)
  381. {
  382. saveBypass = true;
  383. }
  384. else saveBypass = false;
  385.  
  386. if (this.vessel.horizontalSrfSpeed > 0.4 || this.vessel.verticalSpeed > 1.0)
  387. {
  388. saveBypass = true;
  389. }
  390. else saveBypass = false;
  391.  
  392.  
  393. if (this.vessel.parts.Count != lastSavedPartsCount && IDTargetSaved == true) // must be true this is an update check/save not an initialization save.
  394. {
  395. TrySave();
  396. IDTargetSaved = true;
  397. lastSavedPartsCount = this.vessel.parts.Count;
  398. lastSaveTime = Time.time;
  399. ScreenMessages.PostScreenMessage(new ScreenMessage("This is a part count change save", 3f, ScreenMessageStyle.UPPER_CENTER));
  400. //print("This is a part count change save!");
  401. }
  402.  
  403. if (IDTargetSaved == false && this.vessel.isActiveVessel)
  404. {
  405. if (launchSaveTimer > 0f)
  406. {
  407. launchSaveTimer--;
  408.  
  409. if (launchSaveTimer <= 0f)
  410. {
  411. TrySave();
  412. IDTargetSaved = true;
  413. lastSavedPartsCount = this.vessel.parts.Count;
  414. lastSaveTime = Time.time;
  415. ScreenMessages.PostScreenMessage(new ScreenMessage("This is the initial launch save", 4f, ScreenMessageStyle.UPPER_CENTER));
  416. print("This is the initial launch save");
  417.  
  418. }
  419. }
  420.  
  421. }
  422.  
  423. if (IDTargetSaved == true && !this.vessel.isActiveVessel && setTimerOnce == true)
  424. {
  425.  
  426. lastSaveTime = Time.time; //don't save... it's already saved... but we still need to capture a point in time to start the save checks.
  427.  
  428. TryLoad();
  429. lastLoadTime = Time.time;
  430. ScreenMessages.PostScreenMessage(new ScreenMessage("This is a resume-state load for a non controlled vessel", 3f, ScreenMessageStyle.UPPER_CENTER));
  431. //print("This is a resume-state load for a non controlled vessel");
  432.  
  433. setTimerOnce = false;
  434. }
  435.  
  436. if (saveBypass == false)
  437. {
  438.  
  439. if (this.vessel.isActiveVessel && IDTargetSaved == true)
  440. {
  441.  
  442. if (launchLoadTimer > 0f)
  443. {
  444. launchLoadTimer--;
  445.  
  446. if (launchLoadTimer <= 0f)
  447. {
  448. TryLoad();
  449. lastLoadTime = Time.time;
  450.  
  451. //print("This is a timed load, did you just switch to this vessel?");
  452.  
  453. }
  454. }
  455.  
  456.  
  457. }
  458. else if (!this.vessel.isActiveVessel && IDTargetSaved == true && oneStartLoad == true)
  459. {
  460. if (launchLoadTimer > 0f)
  461. {
  462. launchLoadTimer--;
  463.  
  464. if (launchLoadTimer <= 0f)
  465. {
  466. TryLoad();
  467. lastLoadTime = Time.time;
  468. oneStartLoad = false;
  469. }
  470. }
  471. }
  472.  
  473. if (!this.vessel.isActiveVessel && Vector3.Distance(this.vessel.transform.position, FlightGlobals.ActiveVessel.transform.position) < (Vessel.unloadDistance - 500f) && lastSaveTime < Time.time - 30f && setTimerOnce == false || partCountChanged == true)
  474. {
  475. TrySave();
  476. IDTargetSaved = true;
  477. lastSavedPartsCount = this.vessel.parts.Count;
  478. lastSaveTime = Time.time;
  479. partCountChanged = false;
  480. //print("This is a timed save for an uncontrolled vessel!");
  481. //ScreenMessages.PostScreenMessage(new ScreenMessage("This is a timed save for an uncontrolled vessel.", 3f, ScreenMessageStyle.UPPER_CENTER));
  482. }
  483.  
  484. if (!this.vessel.isActiveVessel && Vector3.Distance(this.vessel.transform.position, FlightGlobals.ActiveVessel.transform.position) < (Vessel.loadDistance - 500f) && IDTargetSaved == true && lastLoadTime < Time.time - 120f )
  485. {
  486. TryLoad();
  487. lastLoadTime = Time.time;
  488. //ScreenMessages.PostScreenMessage(new ScreenMessage("This is a timed load for an uncontrolled vessel.", 3f, ScreenMessageStyle.UPPER_CENTER));
  489. //print("This is a timed load for an uncontrolled vessel!");
  490. }
  491.  
  492. }
  493.  
  494. if (!this.vessel.isActiveVessel)
  495. {
  496. if (updateAutoSaveTimer > 0f)
  497. {
  498. updateAutoSaveTimer--;
  499.  
  500. if (updateAutoSaveTimer <= 0f)
  501. {
  502. if (this.vessel.parts.Count != lastSavedPartsCount)
  503. {
  504. partCountChanged = true;
  505. }
  506. updateAutoSaveTimer = 30f;
  507. }
  508. }
  509. }
  510.  
  511.  
  512. if (saveItNow == true)
  513. {
  514. if (doItOnce == true)
  515. {
  516. CPSlist = new List<targetPart>();
  517. int i = 0;
  518.  
  519. foreach (Part p in this.vessel.parts)
  520. {
  521. CPSselect = p.GetComponent<targetPart>();
  522.  
  523. if (CPSselect != null)
  524. {
  525. i++;
  526. savePartCPS = CPSselect.currentPartStructure;
  527. CPSlist.Add(CPSselect);
  528. }
  529.  
  530. }
  531. doItOnce = false;
  532. }
  533.  
  534. saveTime = Time.time;
  535.  
  536. print(saveFileName);
  537.  
  538. System.IO.Directory.CreateDirectory("IDSaveVessels");
  539. string appPath = System.IO.Path.Combine(System.Environment.CurrentDirectory, "IDSaveVessels");
  540. string finalPath = System.IO.Path.Combine(appPath, saveFileName);
  541. TextWriter tw = new StreamWriter(finalPath);
  542.  
  543. // write lines of text to the file
  544. tw.WriteLine(saveTime);
  545. for (int i = 0; i < CPSlist.Count; i++)
  546. {
  547. tw.WriteLine(CPSlist[i].currentPartStructure);
  548. tw.WriteLine(CPSlist[i].fuelLeak);
  549. tw.WriteLine(CPSlist[i].targetBurnedOut);
  550. tw.WriteLine(CPSlist[i].targetIsBurning);
  551. tw.WriteLine(CPSlist[i].torpWaterlinePenetration);
  552. tw.WriteLine(CPSlist[i].weKnowOrigMass);
  553. tw.WriteLine(CPSlist[i].targetStructure);
  554. tw.WriteLine(CPSlist[i].currentMass);
  555.  
  556. }
  557.  
  558. // close the stream
  559. tw.Close();
  560.  
  561. saveItNow = false;
  562. }
  563.  
  564. if (loadItNow == true)
  565. {
  566.  
  567. float checkNumParts = this.vessel.parts.Count;
  568.  
  569. // create reader & open file
  570. string appPath = System.IO.Path.Combine(System.Environment.CurrentDirectory, "IDSaveVessels");
  571. string readPath = System.IO.Path.Combine(appPath, saveFileName);
  572. TextReader tr = new StreamReader(readPath);
  573.  
  574. string recoverSaveTime = tr.ReadLine();
  575. float recoveredSaveTime = (float)Convert.ToDouble(recoverSaveTime);
  576.  
  577. int i = 0;
  578.  
  579. foreach (Part p in this.vessel.parts)
  580. {
  581. CPSselect = p.GetComponent<targetPart>();
  582.  
  583. if (CPSselect != null)
  584. {
  585.  
  586. i++;
  587. string recoverCPS = tr.ReadLine();
  588. string recoverFLeak = tr.ReadLine();
  589. string recoverTBO = tr.ReadLine();
  590. string recoverTIB = tr.ReadLine();
  591. string recoverTWP = tr.ReadLine();
  592. string recoverWKOM = tr.ReadLine();
  593. string recoverTS = tr.ReadLine();
  594. string recoverCM = tr.ReadLine();
  595.  
  596. #region convert text readlines to values
  597. float recoveredCPS = (float)Convert.ToDouble(recoverCPS);
  598.  
  599. bool recover2FLeak, recover2TBO, recover2TIB, recover2TWP, recover2WKOM;
  600.  
  601. if (recoverFLeak == "True")
  602. {
  603. recover2FLeak = true;
  604. }
  605. else recover2FLeak = false;
  606.  
  607. if (recoverTBO == "True")
  608. {
  609. recover2TBO = true;
  610. }
  611. else recover2TBO = false;
  612.  
  613. if (recoverTIB == "True")
  614. {
  615. recover2TIB = true;
  616. }
  617. else recover2TIB = false;
  618.  
  619. if (recoverTWP == "True")
  620. {
  621. recover2TWP = true;
  622. }
  623. else recover2TWP = false;
  624. if (recoverWKOM == "True")
  625. {
  626. recover2WKOM = true;
  627. }
  628. else recover2WKOM = false;
  629.  
  630. float recoveredTS = (float)Convert.ToDouble(recoverTS);
  631.  
  632. float recoveredCM = (float)Convert.ToDouble(recoverCM);
  633.  
  634. #endregion
  635. if (recoveredCPS <= 0f)
  636. {
  637. CPSselect.currentPartStructure = -123f;
  638. Debug.Log("found a part that was previously destroyed and is now being loaded!");
  639. }
  640. else
  641. {
  642. CPSselect.currentPartStructure = recoveredCPS;
  643. }
  644. CPSselect.fuelLeak = recover2FLeak;
  645. CPSselect.targetBurnedOut = recover2TBO;
  646. CPSselect.targetIsBurning = recover2TIB;
  647. CPSselect.torpWaterlinePenetration = recover2TWP;
  648. CPSselect.weKnowOrigMass = recover2WKOM;
  649. CPSselect.targetStructure = recoveredTS;
  650. CPSselect.currentMass = recoveredCM;
  651.  
  652.  
  653. CPSselect.thisPartRestored = true;
  654. }
  655. else
  656. {
  657. TryLoad();
  658. }
  659.  
  660.  
  661. }
  662.  
  663. // close the stream
  664. tr.Close();
  665.  
  666. loadItNow = false;
  667. }
  668.  
  669. }
  670. }
  671.  
  672.  
  673. }
  674.  
  675. **********************************************************IDIFF
  676.  
  677. using System;
  678. using System.Collections.Generic;
  679. using System.Linq;
  680. using System.Text;
  681. using System.Threading.Tasks;
  682. using UnityEngine;
  683.  
  684. [KSPAddon(KSPAddon.Startup.Flight, false)]
  685. public class rangeBooster : MonoBehaviour
  686. {
  687. public bool doItOnce = true;
  688.  
  689. void Start()
  690. {
  691. Vessel.loadDistance = 10250f; //10250f
  692. Vessel.unloadDistance = 10000f; //10000f
  693.  
  694.  
  695. var sceneVessels = FindObjectsOfType(typeof(Vessel)) as Vessel[];
  696. if (sceneVessels != null)
  697. {
  698. foreach (var v in sceneVessels)
  699. {
  700. v.distanceLandedPackThreshold = 8500f;
  701. v.distanceLandedUnpackThreshold = 8000f;
  702. v.distancePackThreshold = 8500f;
  703. v.distanceUnpackThreshold = 8000f;
  704.  
  705. }
  706. }
  707.  
  708.  
  709. }
  710.  
  711. public void Update()
  712. {
  713.  
  714.  
  715. if (Vessel.unloadDistance < 10000f || Vessel.loadDistance < 10250f)
  716. {
  717.  
  718. Vessel.loadDistance = 10250f;
  719. Vessel.unloadDistance = 10000f;
  720.  
  721. var sceneVessels = FindObjectsOfType(typeof(Vessel)) as Vessel[];
  722. if (sceneVessels != null)
  723. {
  724. foreach (var v in sceneVessels)
  725. {
  726. v.distanceLandedPackThreshold = 8500f;
  727. v.distanceLandedUnpackThreshold = 8000f;
  728. v.distancePackThreshold = 8500f;
  729. v.distanceUnpackThreshold = 8000f;
  730.  
  731.  
  732. }
  733. }
  734. }
  735.  
  736.  
  737. }
  738. }
  739.  
  740. *************************************************************** IDrangebooster
  741.  
  742. using System;
  743. using System.Collections.Generic;
  744. using System.Text;
  745. using System.Threading.Tasks;
  746. using UnityEngine;
  747.  
  748.  
  749. [KSPAddon(KSPAddon.Startup.Flight, false)]
  750. public class addDamageModule : MonoBehaviour
  751. {
  752. public bool doItOnce = true;
  753. //bool partsWereChanged = false;
  754. public targetPart checkThisPart;
  755.  
  756. void Start()
  757. {
  758. doItOnce = true;
  759.  
  760.  
  761. if (HighLogic.LoadedSceneIsFlight)
  762. {
  763.  
  764. if (doItOnce == true)
  765. {
  766.  
  767. foreach (Vessel v in FlightGlobals.Vessels)
  768. {
  769. if (!v.isEVA)
  770. {
  771.  
  772. foreach (Part makeTargetPart in v.Parts)
  773. {
  774.  
  775. try
  776. {
  777. checkThisPart = makeTargetPart.GetComponentInChildren<targetPart>();
  778. }
  779. catch
  780. {
  781. //Debug.Log("There was no targetPart on it! Applying targetPart code to Part!");
  782. }
  783.  
  784. if (checkThisPart == null)
  785. {
  786. targetPart tpThis = makeTargetPart.gameObject.AddComponent<targetPart>();
  787. tpThis.objectType = "targetObj";
  788. tpThis.weKnowOrigMass = false;
  789.  
  790. if (makeTargetPart.name.Contains("Carrier") || makeTargetPart.name.Contains("SSN"))
  791. {
  792. Debug.Log("Found an ID Legacy BoatPart, applying structure");
  793. tpThis.targetHardness = 380f;
  794. tpThis.targetNotVoid = 0.01f;
  795. tpThis.targetType = 7f;
  796. }
  797. if (makeTargetPart.name.Contains("Warship"))
  798. {
  799. Debug.Log("Found an ID Warship, applying structure");
  800. tpThis.targetHardness = 390f;
  801. tpThis.targetNotVoid = 0.005f;
  802. tpThis.targetType = 7f;
  803. }
  804.  
  805. if (makeTargetPart.GetComponentInChildren<ModuleEngines>() == true)
  806. {
  807. Debug.Log("Found a stock engine, applying structure");
  808. tpThis.targetHardness = 350f;
  809. tpThis.targetNotVoid = 0.85f;
  810. tpThis.targetType = 5f;
  811. }
  812. if (makeTargetPart.GetComponentInChildren<ModuleControlSurface>() == true || makeTargetPart.GetComponentInChildren<Winglet>() == true)
  813. {
  814. Debug.Log("Found a stock control surface, applying structure");
  815. tpThis.targetNotVoid = 0.75f;
  816. tpThis.targetType = 3f;
  817. }
  818.  
  819. if (makeTargetPart.GetComponentInChildren<CommandPod>() == true)
  820. {
  821. Debug.Log("Found a stock command pod, applying structure");
  822. tpThis.targetHardness = 200f;
  823. tpThis.targetNotVoid = 0.5f;
  824. tpThis.targetType = 4f;
  825. }
  826.  
  827. if (makeTargetPart.GetComponentInChildren<Part>() == true)
  828. {
  829. Part thisPart = makeTargetPart.GetComponentInChildren<Part>();
  830. PartResourceList resourceList = thisPart.Resources;
  831. foreach (PartResource resource in resourceList)
  832. {
  833. if (resource.resourceName == "LiquidFuel")
  834. {
  835. Debug.Log("Found a stock fuel tank, applying structure");
  836. tpThis.targetNotVoid = 0.5f;
  837. tpThis.targetType = 6f;
  838. }
  839. }
  840. }
  841. if (makeTargetPart.name.Contains("FSbomb"))
  842. {
  843. Debug.Log("Found a FS Bomber part.");
  844. tpThis.targetNotVoid = 0.075f;
  845. tpThis.targetHardness = 170f;
  846. tpThis.targetType = 7f;
  847. }
  848. if (makeTargetPart.name.Contains("RepairStation"))
  849. {
  850. Debug.Log("Found a RepairStation part.");
  851. tpThis.targetNotVoid = 0.15f;
  852. tpThis.targetHardness = 220f;
  853. tpThis.targetType = 8f;
  854. }
  855.  
  856. }
  857.  
  858. }
  859.  
  860. }
  861.  
  862. }
  863. doItOnce = false;
  864. }
  865. }
  866.  
  867. }
  868.  
  869. public void Update()
  870. {
  871. if (HighLogic.LoadedSceneIsFlight)
  872. {
  873. if (FlightGlobals.ActiveVessel.verticalSpeed <= 0.5 && FlightGlobals.ActiveVessel.horizontalSrfSpeed <= 0.5)
  874. {
  875. checkIsTarget();
  876. }
  877.  
  878.  
  879. }
  880.  
  881.  
  882.  
  883.  
  884. }
  885.  
  886.  
  887.  
  888. public void checkIsTarget()
  889. {
  890.  
  891. if (HighLogic.LoadedSceneIsFlight)
  892. {
  893.  
  894. foreach (Vessel v in FlightGlobals.Vessels)
  895. {
  896. foreach (Part makeTargetPart in v.Parts)
  897. {
  898.  
  899. if (!makeTargetPart.GetComponent<targetPart>())
  900. {
  901.  
  902. //Debug.Log("There was no targetPart on it! Applying targetPart code to Part!");
  903. targetPart tpThis = makeTargetPart.gameObject.AddComponent<targetPart>();
  904. tpThis.objectType = "targetObj";
  905. tpThis.firstRun = true;
  906. tpThis.weKnowOrigMass = false;
  907.  
  908. if (makeTargetPart.GetComponentInChildren<ModuleEngines>() == true)
  909. {
  910. Debug.Log("Found a stock engine, applying structure");
  911. tpThis.targetHardness = 350f;
  912. tpThis.targetNotVoid = 1f;
  913. tpThis.targetType = 5f;
  914. }
  915. if (makeTargetPart.GetComponentInChildren<ModuleControlSurface>() == true || makeTargetPart.GetComponentInChildren<Winglet>() == true)
  916. {
  917. Debug.Log("Found a stock control surface, applying structure");
  918. tpThis.targetNotVoid = 0.75f;
  919. tpThis.targetType = 3f;
  920. }
  921.  
  922. if (makeTargetPart.GetComponentInChildren<CommandPod>() == true)
  923. {
  924. Debug.Log("Found a stock command pod, applying structure");
  925. tpThis.targetNotVoid = 0.5f;
  926. tpThis.targetType = 4f;
  927. }
  928.  
  929. if (makeTargetPart.GetComponentInChildren<Part>() == true)
  930. {
  931. Part thisPart = makeTargetPart.GetComponentInChildren<Part>();
  932. PartResourceList resourceList = thisPart.Resources;
  933. foreach (PartResource resource in resourceList)
  934. {
  935. if (resource.resourceName == "LiquidFuel")
  936. {
  937. Debug.Log("Found a stock fuel tank, applying structure");
  938. tpThis.targetNotVoid = 0.4f;
  939. tpThis.targetType = 6f;
  940. }
  941. }
  942.  
  943. }
  944. if (makeTargetPart.name.Contains("FSbomb"))
  945. {
  946. Debug.Log("Found a FS Bomber part.");
  947. tpThis.targetNotVoid = 0.075f;
  948. tpThis.targetHardness = 170f;
  949. tpThis.targetType = 7f;
  950. }
  951.  
  952. }
  953.  
  954.  
  955.  
  956. }
  957.  
  958.  
  959. }
  960.  
  961.  
  962.  
  963. }
  964. }
  965. }
  966.  
  967. [KSPAddon(KSPAddon.Startup.Flight, false)]
  968. public class IFFList : MonoBehaviour
  969. {
  970. public bool doItOnce = true;
  971. public targetPart checkThisPart;
  972.  
  973. public static IFFList Instance = null;
  974.  
  975. public int lastVesselCount;
  976.  
  977. public float updateListTimer = 900f;
  978.  
  979. //public List
  980.  
  981. private List<Vessel> getAllIFFRed = new List<Vessel>();
  982. private List<Vessel> getAllIFFBlue = new List<Vessel>();
  983.  
  984. public List<Vessel> IFFRed()
  985. {
  986. return Instance.getAllIFFRed;
  987. }
  988.  
  989. public List<Vessel> IFFBlue()
  990. {
  991. return Instance.getAllIFFBlue;
  992. }
  993.  
  994.  
  995. public void Awake()
  996. {
  997.  
  998.  
  999. Instance = this;
  1000. lastVesselCount = 0;
  1001. }
  1002.  
  1003. public void FixedUpdate()
  1004. {
  1005. if (HighLogic.LoadedSceneIsFlight)
  1006. {
  1007.  
  1008. if (FlightGlobals.Vessels.Count != lastVesselCount)
  1009. {
  1010. alterTheLists();
  1011.  
  1012. lastVesselCount = FlightGlobals.Vessels.Count;
  1013. }
  1014.  
  1015. if (updateListTimer > 0f)
  1016. {
  1017. updateListTimer--;
  1018.  
  1019. if (updateListTimer <= 0f)
  1020. {
  1021. alterTheLists();
  1022.  
  1023. updateListTimer = 300f;
  1024. }
  1025. }
  1026.  
  1027.  
  1028. }
  1029. }
  1030.  
  1031. public void alterTheLists()
  1032. {
  1033. getAllIFFBlue.Clear();
  1034. getAllIFFRed.Clear();
  1035.  
  1036. foreach (Vessel aVessel in FlightGlobals.Vessels)
  1037. {
  1038. foreach (Part aPart in aVessel.Parts)
  1039. {
  1040. foreach (PartModule aModule in aPart.Modules)
  1041. {
  1042. if (aModule is relayIFF)
  1043. {
  1044. relayIFF thisIFF = aModule.GetComponent<relayIFF>();
  1045.  
  1046. if (thisIFF.setIFF == "red")
  1047. {
  1048. if (!getAllIFFRed.Contains(thisIFF.vessel))
  1049. {
  1050. getAllIFFRed.Add(thisIFF.vessel);//place it
  1051.  
  1052. }
  1053. if (getAllIFFBlue.Contains(thisIFF.vessel))
  1054. {
  1055. getAllIFFBlue.Remove(thisIFF.vessel);
  1056.  
  1057. }
  1058.  
  1059.  
  1060. }
  1061. if (thisIFF.setIFF == "blue")
  1062. {
  1063. if (!getAllIFFBlue.Contains(thisIFF.vessel))
  1064. {
  1065. getAllIFFBlue.Add(thisIFF.vessel);
  1066.  
  1067. }
  1068. if (getAllIFFRed.Contains(thisIFF.vessel))
  1069. {
  1070. getAllIFFRed.Remove(thisIFF.vessel);//place it
  1071.  
  1072. }
  1073.  
  1074.  
  1075. }
  1076. }
  1077. }
  1078.  
  1079. }
  1080. }
  1081.  
  1082. lastVesselCount = FlightGlobals.Vessels.Count;
  1083. }
  1084.  
  1085. }
  1086.  
  1087. ******************************************************************IDbaseweapons
  1088.  
  1089. using System;
  1090. using System.Collections.Generic;
  1091. using System.Linq;
  1092. using System.Text;
  1093. using System.Threading.Tasks;
  1094. using UnityEngine;
  1095.  
  1096.  
  1097. public class IDHardPoint : PartModule
  1098. {
  1099. public Transform hardPoint;
  1100. public Transform[] multiPoints;
  1101.  
  1102. public bool doItOnce = true;
  1103. public bool sAWHSafe = true;
  1104.  
  1105. [KSPField(guiActive = false, isPersistant = true)]
  1106. public bool isRocketPod = false;
  1107.  
  1108. [KSPField(guiActive = false, isPersistant = true)]
  1109. public float podRockets = 1f;
  1110.  
  1111. [KSPField(guiActive = false, isPersistant = true)]
  1112. public float rocPodSize = 1f;
  1113.  
  1114. [KSPField(guiActive = false, isPersistant = true)]
  1115. public string ordPath = "IDSkillfulR1/Parts/IDMk82Bomb/model";
  1116.  
  1117. [KSPField(guiActive = false, isPersistant = true)]
  1118. public string ordType = "Nil";
  1119.  
  1120. [KSPField(guiActive = false, isPersistant = true)]
  1121. public bool isStandalone = false;
  1122.  
  1123. public int chosenOrd = 0;
  1124.  
  1125. public bool ordChanged = false;
  1126.  
  1127. public int chosenWHead = 1;
  1128.  
  1129. public int numOfOrdTypes = 7;
  1130.  
  1131. public int numOfRocTypes = 3;
  1132.  
  1133. public int numOfWHTypes = 3;
  1134.  
  1135. public float partRadius;
  1136.  
  1137. public GameObject ordinanceInstance;
  1138. public GameObject[] multiInstances;
  1139.  
  1140. public Vector3 thisWayUp;
  1141.  
  1142. [KSPField(guiActive = true, isPersistant = true)]
  1143. public string loadedName = "Nil";
  1144.  
  1145. [KSPField(guiActive = false, isPersistant = true)]
  1146. public float emptyMass = 0f;
  1147.  
  1148. [KSPField(guiActive = false, isPersistant = true)]
  1149. public float emptyMDrag = 0f;
  1150.  
  1151. [KSPField(guiActive = false, isPersistant = true)]
  1152. public float emptyDrag = 0f;
  1153.  
  1154. [KSPField(guiActive = false, isPersistant = true)]
  1155. public float emptyADrag = 0f;
  1156.  
  1157. [KSPField(guiActive = false, isPersistant = true)]
  1158. public bool getEmptyValues = true;
  1159.  
  1160. public float ordMass, ordDrag, ordMDrag, ordADrag, ordRDelay, ordRDrag;
  1161.  
  1162. public float ordHardness;
  1163.  
  1164. public bool ordIsRetarded, ordIsAirBurst, ordIsClusterBomb, ordIsTorpedo, ordIsRocket;
  1165.  
  1166. [KSPField]
  1167. public float ordTorpThrust = 5f;
  1168.  
  1169. [KSPField]
  1170. public float ordTorpRTimer = 5000f;
  1171.  
  1172. [KSPField]
  1173. public float ordRocSize = 1f;
  1174.  
  1175. [KSPField(guiActive = false, isPersistant = true)]
  1176. public float warheadType = 1f;
  1177.  
  1178. [KSPField(guiActive = true, isPersistant = true)]
  1179. public string showWHType = "HE";
  1180.  
  1181. public double ordBurstAlt;
  1182.  
  1183. public int ordClusterBomblets;
  1184.  
  1185. [KSPField(guiActive = false, isPersistant = true)]
  1186. public bool bombLoaded = false;
  1187.  
  1188. public GameObject bombCollider;
  1189.  
  1190. public bool bombsAway = false;
  1191.  
  1192. public bool onePack = true;
  1193.  
  1194. public Transform sendHoldHeading;
  1195.  
  1196. public bool positionChanged = false;
  1197.  
  1198.  
  1199. [KSPEvent(name = "chooseWHead", active = true, guiActiveUnfocused = true, externalToEVAOnly = true, guiActive = false, guiActiveEditor = true, unfocusedRange = 5f, guiName = "Choose Warhead")]
  1200. public void letsChooseWarhead()
  1201. {
  1202. chosenWHead += 1;
  1203. if (chosenWHead > numOfWHTypes) chosenWHead = 1;
  1204.  
  1205. if (chosenWHead == 1)
  1206. {
  1207. showWHType = "HE";
  1208. ScreenMessages.PostScreenMessage(new ScreenMessage("HE - High Explosive", 3f, ScreenMessageStyle.UPPER_CENTER));
  1209. }
  1210. if (chosenWHead == 2)
  1211. {
  1212. showWHType = "Incen.";
  1213. ScreenMessages.PostScreenMessage(new ScreenMessage("Incendiary", 3f, ScreenMessageStyle.UPPER_CENTER));
  1214. }
  1215. if (chosenWHead == 3)
  1216. {
  1217. showWHType = "AP";
  1218. ScreenMessages.PostScreenMessage(new ScreenMessage("AP - Armour Piercing", 3f, ScreenMessageStyle.UPPER_CENTER));
  1219. }
  1220.  
  1221. warheadType = (float)chosenWHead;
  1222.  
  1223. }
  1224.  
  1225. [KSPEvent(name = "chooseOrd", active = true, guiActiveUnfocused = true, externalToEVAOnly = true, guiActive = false, guiActiveEditor = true, unfocusedRange = 5f, guiName = "Choose Ordnance")]
  1226. public void letsChooseOrd()
  1227. {
  1228. ordChanged = true;
  1229.  
  1230. if (!isRocketPod)
  1231. {
  1232. chosenOrd += 1;
  1233. if (chosenOrd > numOfOrdTypes) chosenOrd = 1;
  1234. if (chosenOrd == 1)
  1235. {
  1236. ordPath = "";
  1237. ordType = "Nil";
  1238. ScreenMessages.PostScreenMessage(new ScreenMessage("Hardpoint Empty!", 3f, ScreenMessageStyle.UPPER_CENTER));
  1239. }
  1240. if (chosenOrd == 2)
  1241. {
  1242. ordPath = "IDSkillfulR1/Parts/IDWW1Bomb/model";
  1243. ordType = "WW1Bomb125lb";
  1244. ScreenMessages.PostScreenMessage(new ScreenMessage("Load with WW1 125lb Bomb", 3f, ScreenMessageStyle.UPPER_CENTER));
  1245. }
  1246. if (chosenOrd == 3)
  1247. {
  1248. ordPath = "IDSkillfulR1/Parts/IDWW1Bomb/model";
  1249. ordType = "WW1Bomb250lb";
  1250. ScreenMessages.PostScreenMessage(new ScreenMessage("Load with WW1 250lb Bomb", 3f, ScreenMessageStyle.UPPER_CENTER));
  1251. }
  1252. if (chosenOrd == 4)
  1253. {
  1254. ordPath = "IDSkillfulR1/Parts/IDMk84Bomb/model";
  1255. ordType = "Mk82Cluster";
  1256. ScreenMessages.PostScreenMessage(new ScreenMessage("Load with Mk82 500lb Bomb", 3f, ScreenMessageStyle.UPPER_CENTER));
  1257. }
  1258. if (chosenOrd == 5)
  1259. {
  1260. ordPath = "IDSkillfulR1/Parts/IDMk84Bomb/model";
  1261. ordType = "Mk84Retarded";
  1262. ScreenMessages.PostScreenMessage(new ScreenMessage("Load with Mk84 2000lb Bomb", 3f, ScreenMessageStyle.UPPER_CENTER));
  1263. }
  1264. if (chosenOrd == 6)
  1265. {
  1266. ordPath = "IDSkillfulR1/Parts/IDMk84Bomb/model";
  1267. ordType = "TallBoy";
  1268. ScreenMessages.PostScreenMessage(new ScreenMessage("Load with 12000lb TallBoy Bomb", 3f, ScreenMessageStyle.UPPER_CENTER));
  1269. }
  1270. if (chosenOrd == 7)
  1271. {
  1272. ordPath = "IDSkillfulR1/Parts/IDType91T/model";
  1273. ordType = "Type91T";
  1274. ScreenMessages.PostScreenMessage(new ScreenMessage("Load with Type 91t Torpedo", 3f, ScreenMessageStyle.UPPER_CENTER));
  1275. }
  1276.  
  1277.  
  1278. }
  1279. else
  1280. {
  1281. chosenOrd += 1;
  1282. if (chosenOrd > numOfRocTypes) chosenOrd = 1;
  1283.  
  1284. if (chosenOrd == 1)
  1285. {
  1286. ordPath = "";
  1287. ordType = "Nil";
  1288. ScreenMessages.PostScreenMessage(new ScreenMessage("Hardpoint Empty!", 3f, ScreenMessageStyle.UPPER_CENTER));
  1289. }
  1290. if (chosenOrd == 2)
  1291. {
  1292. ordPath = "IDSkillfulR1/Parts/IDlau68Rocket/model";
  1293. ordType = "lau68Rocket";
  1294.  
  1295. ScreenMessages.PostScreenMessage(new ScreenMessage("Load with lau68 Rockets", 3f, ScreenMessageStyle.UPPER_CENTER));
  1296. }
  1297. if (chosenOrd == 3 && rocPodSize > 1f)
  1298. {
  1299. ordPath = "IDSkillfulR1/Parts/IDlau68Rocket/model";
  1300. ordType = "hellfireRocket";
  1301. ScreenMessages.PostScreenMessage(new ScreenMessage("Load with Hellfire Rocket", 3f, ScreenMessageStyle.UPPER_CENTER));
  1302. }
  1303.  
  1304. }
  1305. }
  1306.  
  1307.  
  1308. [KSPEvent(name = "loadHardPoint", active = true, guiActiveUnfocused = true, externalToEVAOnly = true, guiActive = false, guiActiveEditor = true, unfocusedRange = 5f, guiName = "Load Ordnance")]
  1309. public void letsLoadHardPoint()
  1310. {
  1311.  
  1312. doBombSet();
  1313.  
  1314. }
  1315.  
  1316. [KSPEvent(name = "triggerBombDrop", active = true, guiActive = true, guiName = "Release")]
  1317. public void doDropBomb()
  1318. {
  1319.  
  1320. if (bombLoaded == true)
  1321. {
  1322. bombsAway = true;
  1323. }
  1324. if (bombLoaded == false)
  1325. {
  1326. ScreenMessages.PostScreenMessage(new ScreenMessage("No Bomb on Hardpoint!", 4f, ScreenMessageStyle.UPPER_CENTER));
  1327. //print("No Bomb on Hardpoint!");
  1328. }
  1329. }
  1330.  
  1331.  
  1332. [KSPAction("Release Bomb")]
  1333. public void actBombDrop(KSPActionParam param)
  1334. {
  1335. doDropBomb();
  1336. }
  1337.  
  1338.  
  1339.  
  1340. public override void OnStart(StartState state)
  1341. {
  1342. base.OnStart(state);
  1343.  
  1344. if (podRockets > 1f && isRocketPod == true)
  1345. {
  1346.  
  1347. multiPoints = this.part.FindModelTransforms("loadPoint");
  1348.  
  1349. //print("Found enough locations for " + multiPoints.Count() + " rockets!");
  1350.  
  1351. if (getEmptyValues == true && multiPoints.Count() > 1)
  1352. {
  1353. emptyDrag = this.part.minimum_drag;
  1354. emptyMass = this.part.mass;
  1355. emptyMDrag = this.part.maximum_drag;
  1356. emptyADrag = this.part.angularDrag;
  1357.  
  1358. getEmptyValues = false;
  1359.  
  1360. }
  1361.  
  1362.  
  1363. }
  1364. else
  1365. {
  1366. if (hardPoint == null)
  1367. {
  1368. try
  1369. {
  1370. hardPoint = this.part.FindModelTransform("loadPoint");
  1371. }
  1372. catch
  1373. {
  1374. print("Problem locating loadPoint!");
  1375. }
  1376.  
  1377. if (getEmptyValues == true && hardPoint != null)
  1378. {
  1379. emptyDrag = this.part.minimum_drag;
  1380. emptyMass = this.part.mass;
  1381. emptyMDrag = this.part.maximum_drag;
  1382. emptyADrag = this.part.angularDrag;
  1383.  
  1384. getEmptyValues = false;
  1385.  
  1386. }
  1387. }
  1388. }
  1389.  
  1390.  
  1391. }
  1392.  
  1393. public void FixedUpdate()
  1394. {
  1395. if (HighLogic.LoadedSceneIsFlight)
  1396. {
  1397. #region Standalone Warhead
  1398. //if (isStandalone == true && doItOnce == false && sAComponent != null && sAComponent.transform.parent != null)
  1399. //{
  1400. // if (this.transform.position != sAComponent.transform.position)
  1401. // {
  1402. // sAComponent.transform.position = this.transform.position + transform.forward * 8f;
  1403. // sAComponent.transform.rotation = this.transform.rotation;
  1404. // //sAComponent.transform.parent = this.part.transform;
  1405. // }
  1406. // if (rigidbody == null)
  1407. // {
  1408. // Rigidbody rb = sAComponent.AddComponent<Rigidbody>();
  1409.  
  1410. // rb.detectCollisions = true;
  1411. // rb.collisionDetectionMode = CollisionDetectionMode.Continuous;
  1412. // rb.mass = this.part.mass;
  1413. // rb.drag = rndNumber.rndFloat(0.1f, 0.25f);
  1414. // rb.collider.isTrigger = true;
  1415. // }
  1416. //}
  1417.  
  1418.  
  1419. //if (isStandalone == true && doItOnce == true && sAWHSafe == false)
  1420. //{
  1421. // //not implemented yet, requires instantiating a trigger collider/rigidbody to the front of the vessel...
  1422. // //can't remove rigidbodies with joints, and the stock rigidbody/collider structure will not work with skillful.
  1423.  
  1424. // if (sAComponent == null)
  1425. // {
  1426. // sAComponent = GameObject.CreatePrimitive(PrimitiveType.Cube);
  1427. // sAComponent.SetActive(true);
  1428. // sAComponent.renderer.enabled = true;
  1429. // sAComponent.transform.localScale = new Vector3(4f, 4f, 1f); // gameObject.transform.localScale.Set(0.05f, 0.05f, 0.05f);
  1430. // sAComponent.transform.position = this.transform.position + transform.forward * 8f;
  1431. // sAComponent.transform.rotation = this.transform.rotation;
  1432.  
  1433. // sAComponent.transform.parent = this.part.transform;
  1434.  
  1435. // Rigidbody rb = sAComponent.AddComponent<Rigidbody>();
  1436.  
  1437. // rb.detectCollisions = true;
  1438. // rb.collisionDetectionMode = CollisionDetectionMode.Continuous;
  1439. // rb.mass = this.part.mass;
  1440. // rb.drag = rndNumber.rndFloat(0.1f, 0.25f);
  1441.  
  1442. // }
  1443.  
  1444. // IDDropBomb bombPart = this.gameObject.AddComponent<IDDropBomb>();
  1445. // //print("added IDbombdrop");
  1446. // bombPart.isRetarded = ordIsRetarded;
  1447. // bombPart.retardDelay = ordRDelay;
  1448. // bombPart.retardDrag = ordRDrag;
  1449. // bombPart.isAirBurst = ordIsAirBurst;
  1450. // bombPart.burstAlt = ordBurstAlt;
  1451. // bombPart.isClusterBomb = ordIsClusterBomb;
  1452. // bombPart.isTorpedo = ordIsTorpedo;
  1453. // bombPart.isRocket = ordIsRocket;
  1454.  
  1455. // bombPart.holdTorpHeading = sendHoldHeading;
  1456. // bombPart.torpedoLifeTimer = ordTorpRTimer;
  1457. // bombPart.torpedoThrust = ordTorpThrust;
  1458. // bombPart.clusterBomblets = ordClusterBomblets;
  1459. // bombPart.isHardness = ordHardness;
  1460. // bombPart.isWarheadType = warheadType;
  1461.  
  1462. // doItOnce = false;
  1463. //}
  1464. #endregion
  1465.  
  1466. thisWayUp = (this.transform.position - FlightGlobals.ActiveVessel.mainBody.position).normalized;
  1467.  
  1468.  
  1469. if (hardPoint != null && podRockets <= 1f || multiPoints.Count() > 1 && podRockets > 1f)
  1470. {
  1471. if (bombLoaded == true && loadedName != "Nil" && doItOnce == true || bombLoaded == true && ordChanged == true)
  1472. {
  1473.  
  1474. doItOnce = false;
  1475.  
  1476. doBombSet();
  1477. ordChanged = false;
  1478.  
  1479. if (showWHType == "HE")
  1480. {
  1481. warheadType = 1f;
  1482. }
  1483. if (showWHType == "Incen.")
  1484. {
  1485. warheadType = 2f;
  1486. }
  1487. if (showWHType == "AP")
  1488. {
  1489. warheadType = 3f;
  1490. }
  1491. }
  1492.  
  1493. if (bombsAway == true)
  1494. {
  1495. bombsAway = false;
  1496. bombLoaded = false;
  1497. onePack = true;
  1498.  
  1499. if (loadedName != "Nil")
  1500. {
  1501. loadedName = "Nil";
  1502. this.part.mass = emptyMass;
  1503. this.part.maximum_drag = emptyMDrag;
  1504. this.part.minimum_drag = emptyDrag;
  1505. this.part.angularDrag = emptyADrag;
  1506.  
  1507. }
  1508.  
  1509. if (podRockets < 2f || !isRocketPod)
  1510. {
  1511.  
  1512. Rigidbody ordRigidB = ordinanceInstance.AddComponent<Rigidbody>();
  1513. if (ordinanceInstance.rigidbody != null)
  1514. {
  1515.  
  1516. ordRigidB.velocity = this.vessel.rigidbody.velocity;
  1517.  
  1518. ordRigidB.mass = ordMass;
  1519.  
  1520. ordRigidB.drag = ordMDrag;
  1521.  
  1522. ordRigidB.angularDrag = ordADrag;
  1523.  
  1524. ordRigidB.detectCollisions = true;
  1525.  
  1526. ordRigidB.collisionDetectionMode = CollisionDetectionMode.Continuous;
  1527.  
  1528. if (ordIsRocket == true)
  1529. {
  1530. ordRigidB.useGravity = false;
  1531. }
  1532.  
  1533. }
  1534.  
  1535. sendHoldHeading = hardPoint;
  1536.  
  1537. IDDropBomb bombPart = ordinanceInstance.AddComponent<IDDropBomb>();
  1538.  
  1539. bombPart.isRetarded = ordIsRetarded;
  1540. bombPart.retardDelay = ordRDelay;
  1541. bombPart.retardDrag = ordRDrag;
  1542. bombPart.isAirBurst = ordIsAirBurst;
  1543. bombPart.burstAlt = ordBurstAlt;
  1544. bombPart.isClusterBomb = ordIsClusterBomb;
  1545. bombPart.isTorpedo = ordIsTorpedo;
  1546. bombPart.isRocket = ordIsRocket;
  1547. bombPart.holdTorpHeading = sendHoldHeading;
  1548. bombPart.torpedoLifeTimer = ordTorpRTimer;
  1549. bombPart.torpedoThrust = ordTorpThrust;
  1550. bombPart.clusterBomblets = ordClusterBomblets;
  1551. bombPart.isHardness = ordHardness;
  1552. bombPart.isWarheadType = warheadType;
  1553.  
  1554. ordinanceInstance.transform.parent = null;
  1555.  
  1556.  
  1557. }
  1558. if (multiPoints.Count() > 1)
  1559. {
  1560.  
  1561. foreach (GameObject rocketObj in multiInstances)
  1562. {
  1563. Rigidbody ordRigidB = rocketObj.AddComponent<Rigidbody>();
  1564. if (rocketObj.rigidbody != null)
  1565. {
  1566.  
  1567. ordRigidB.velocity = this.vessel.rigidbody.velocity;
  1568.  
  1569. ordRigidB.mass = ordMass;
  1570.  
  1571. ordRigidB.drag = ordMDrag;
  1572.  
  1573. ordRigidB.angularDrag = ordADrag;
  1574.  
  1575. ordRigidB.detectCollisions = true;
  1576.  
  1577. ordRigidB.collisionDetectionMode = CollisionDetectionMode.Continuous;
  1578.  
  1579. if (ordIsRocket == true)
  1580. {
  1581. ordRigidB.useGravity = false;
  1582. }
  1583.  
  1584. }
  1585.  
  1586. sendHoldHeading = multiPoints[0];
  1587.  
  1588. IDDropBomb bombPart = rocketObj.AddComponent<IDDropBomb>();
  1589.  
  1590. bombPart.isRetarded = ordIsRetarded;
  1591. bombPart.retardDelay = ordRDelay;
  1592. bombPart.retardDrag = ordRDrag;
  1593. bombPart.isAirBurst = ordIsAirBurst;
  1594. bombPart.burstAlt = ordBurstAlt;
  1595. bombPart.isClusterBomb = ordIsClusterBomb;
  1596. bombPart.isTorpedo = ordIsTorpedo;
  1597. bombPart.isRocket = ordIsRocket;
  1598. bombPart.holdTorpHeading = sendHoldHeading;
  1599. bombPart.torpedoLifeTimer = ordTorpRTimer;
  1600. bombPart.torpedoThrust = ordTorpThrust;
  1601. bombPart.clusterBomblets = ordClusterBomblets;
  1602. bombPart.isHardness = ordHardness;
  1603. bombPart.isWarheadType = warheadType;
  1604.  
  1605. rocketObj.transform.parent = null;
  1606.  
  1607. }
  1608.  
  1609.  
  1610. }
  1611.  
  1612. }
  1613. }
  1614.  
  1615. }
  1616. }
  1617.  
  1618. public void doBombSet()
  1619. {
  1620. bool stopRepet = true;
  1621.  
  1622. if (bombLoaded == true && loadedName != ordType)
  1623. {
  1624. //print("in here1");
  1625. if (ordinanceInstance != null)
  1626. {
  1627.  
  1628. Destroy(ordinanceInstance);
  1629. foreach (GameObject i in multiInstances)
  1630. {
  1631. Destroy(i);
  1632. onePack = true;
  1633. }
  1634. }
  1635. }
  1636. if (ordinanceInstance == null && ordType != "Nil")
  1637. {
  1638. //print("in here2");
  1639.  
  1640.  
  1641.  
  1642. if (isRocketPod && podRockets > 1f && onePack == true) //&& bombLoaded == false
  1643. {
  1644. //print("in here3");
  1645. int i = 0;
  1646.  
  1647. multiInstances = new GameObject[(int)podRockets];
  1648.  
  1649. foreach (Transform tR in multiPoints)
  1650. {
  1651.  
  1652.  
  1653. try
  1654. {
  1655. multiInstances[i] = GameDatabase.Instance.GetModel(ordPath);
  1656. }
  1657. catch
  1658. {
  1659. print("Problem locating loadPoint!");
  1660. }
  1661.  
  1662. if (multiInstances[i] != null && stopRepet == true)
  1663. {
  1664. //print("in here4");
  1665. if (ordType == "lau68Rocket")
  1666. {
  1667. loadedName = "lau68Rocket";
  1668.  
  1669. ordMass = 0.008f;
  1670. ordHardness = 420f;
  1671. warheadType = (float)chosenWHead;
  1672. ordDrag = 0.7f;
  1673. ordMDrag = 0.7f;
  1674. ordADrag = 1f;
  1675. partRadius = 0.015f; //0.01625f
  1676. ordIsRetarded = false;
  1677. ordRDelay = 0f;
  1678. ordRDrag = 0f;
  1679. ordIsAirBurst = false;
  1680. ordBurstAlt = 0.0;
  1681. ordIsClusterBomb = false;
  1682. ordClusterBomblets = 0;
  1683. ordIsTorpedo = false;
  1684. ordIsRocket = true;
  1685. ordRocSize = 1f;
  1686. ordTorpThrust = 1.4f;
  1687. ordTorpRTimer = 500f;
  1688.  
  1689. }
  1690.  
  1691.  
  1692. multiInstances[i].SetActive(true);
  1693.  
  1694. multiInstances[i].transform.position = tR.position - (tR.up.normalized * partRadius);
  1695. multiInstances[i].transform.rotation = tR.rotation;
  1696.  
  1697. multiInstances[i].transform.parent = this.part.transform;
  1698. }
  1699.  
  1700. if (i == (int)podRockets)
  1701. {
  1702. stopRepet = false;
  1703. }
  1704.  
  1705. i++;
  1706. }
  1707. bombLoaded = true;
  1708. onePack = false;
  1709. }
  1710. else
  1711. {
  1712. //print("in here5");
  1713. try
  1714. {
  1715. ordinanceInstance = GameDatabase.Instance.GetModel(ordPath);
  1716.  
  1717. }
  1718. catch
  1719. {
  1720. print("Problem locating loadPoint!");
  1721. }
  1722.  
  1723. if (ordinanceInstance != null)
  1724. {
  1725.  
  1726. if (ordType == "WW1Bomb125lb")
  1727. {
  1728. loadedName = "WW1Bomb125lb";
  1729. ordinanceInstance.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
  1730. ordMass = 0.0625f;
  1731. ordHardness = 350f;
  1732. warheadType = (float)chosenWHead;
  1733. ordDrag = 0.2f;
  1734. ordMDrag = 0.3f;
  1735. ordADrag = 0.8f;
  1736. partRadius = 0.1f;
  1737. ordIsRetarded = false;
  1738. ordRDelay = 0f;
  1739. ordRDrag = 0f;
  1740. ordIsAirBurst = false;
  1741. ordBurstAlt = 250.0;
  1742. ordIsClusterBomb = false;
  1743. ordClusterBomblets = 0;
  1744. ordIsTorpedo = false;
  1745. ordIsRocket = false;
  1746. ordRocSize = 0f;
  1747. ordTorpThrust = 0f;
  1748. ordTorpRTimer = 0f;
  1749.  
  1750. }
  1751. if (ordType == "WW1Bomb250lb")
  1752. {
  1753. loadedName = "WW1Bomb250lb";
  1754. ordinanceInstance.transform.localScale = new Vector3(0.75f, 0.75f, 0.75f);
  1755. ordMass = 0.125f;
  1756. ordHardness = 350f;
  1757. warheadType = (float)chosenWHead;
  1758. ordDrag = 0.2f;
  1759. ordMDrag = 0.3f;
  1760. ordADrag = 0.8f;
  1761. partRadius = 0.125f;
  1762. ordIsRetarded = false;
  1763. ordRDelay = 0f;
  1764. ordRDrag = 0f;
  1765. ordIsAirBurst = false;
  1766. ordBurstAlt = 250.0;
  1767. ordIsClusterBomb = false;
  1768. ordClusterBomblets = 0;
  1769. ordIsTorpedo = false;
  1770. ordIsRocket = false;
  1771. ordRocSize = 0f;
  1772. ordTorpThrust = 0f;
  1773. ordTorpRTimer = 0f;
  1774.  
  1775. }
  1776. if (ordType == "Mk82Cluster")
  1777. {
  1778. loadedName = "Mk82Cluster";
  1779. ordinanceInstance.transform.localScale = new Vector3(0.75f, 0.75f, 0.75f); // this bomb uses the same model but at 75% the size.
  1780. ordMass = 0.25f;
  1781. ordHardness = 350f;
  1782. warheadType = (float)chosenWHead;
  1783. ordDrag = 0.2f;
  1784. ordMDrag = 0.3f;
  1785. ordADrag = 1f;
  1786. partRadius = 0.16f;
  1787. ordIsRetarded = false;
  1788. ordRDelay = 0f;
  1789. ordRDrag = 0f;
  1790. ordIsAirBurst = false;
  1791. ordBurstAlt = 250.0;
  1792. ordIsClusterBomb = true;
  1793. ordClusterBomblets = 24;
  1794. ordIsTorpedo = false;
  1795. ordIsRocket = false;
  1796. ordRocSize = 0f;
  1797. ordTorpThrust = 0f;
  1798. ordTorpRTimer = 0f;
  1799.  
  1800. }
  1801. if (ordType == "Mk84Retarded")
  1802. {
  1803. loadedName = "Mk84Retarded";
  1804. ordinanceInstance.transform.localScale = new Vector3(1f, 1f, 1f);
  1805. ordMass = 1f;
  1806. ordHardness = 350f;
  1807. warheadType = (float)chosenWHead;
  1808. ordDrag = 0.2f;
  1809. ordMDrag = 0.3f;
  1810. ordADrag = 1f;
  1811. partRadius = 0.2765f;
  1812. ordIsRetarded = true;
  1813. ordRDelay = 1f;
  1814. ordRDrag = 0.5f;
  1815. ordIsAirBurst = false;
  1816. ordBurstAlt = 0.0;
  1817. ordIsClusterBomb = false;
  1818. ordClusterBomblets = 0;
  1819. ordIsTorpedo = false;
  1820. ordIsRocket = false;
  1821. ordRocSize = 0f;
  1822. ordTorpThrust = 0f;
  1823. ordTorpRTimer = 0f;
  1824.  
  1825. }
  1826. if (ordType == "TallBoy")
  1827. {
  1828. loadedName = "TallBoy";
  1829. ordinanceInstance.transform.localScale = new Vector3(2f, 2f, 2f);
  1830. ordMass = 5.4f;
  1831. ordHardness = 350f;
  1832. warheadType = (float)chosenWHead;
  1833. ordDrag = 0.2f;
  1834. ordMDrag = 0.3f;
  1835. ordADrag = 1f;
  1836. partRadius = 0.485f;
  1837. ordIsRetarded = false;
  1838. ordRDelay = 0f;
  1839. ordRDrag = 0f;
  1840. ordIsAirBurst = false;
  1841. ordBurstAlt = 0.0;
  1842. ordIsClusterBomb = false;
  1843. ordClusterBomblets = 0;
  1844. ordIsTorpedo = false;
  1845. ordIsRocket = false;
  1846. ordRocSize = 0f;
  1847. ordTorpThrust = 0f;
  1848. ordTorpRTimer = 0f;
  1849.  
  1850. }
  1851. if (ordType == "Type91T")
  1852. {
  1853. loadedName = "Type91T";
  1854.  
  1855. ordMass = 1.12f;
  1856. ordHardness = 350f;
  1857. warheadType = (float)chosenWHead;
  1858. ordDrag = 0.2f;
  1859. ordMDrag = 0.3f;
  1860. ordADrag = 1f;
  1861. partRadius = 0.325f;
  1862. ordIsRetarded = false;
  1863. ordRDelay = 0f;
  1864. ordRDrag = 0f;
  1865. ordIsAirBurst = false;
  1866. ordBurstAlt = 0.0;
  1867. ordIsClusterBomb = false;
  1868. ordClusterBomblets = 0;
  1869. ordIsTorpedo = true;
  1870. ordIsRocket = false;
  1871. ordRocSize = 0f;
  1872. ordTorpThrust = 9f;
  1873. ordTorpRTimer = 7500f;
  1874.  
  1875. }
  1876. if (ordType == "lau68Rocket")
  1877. {
  1878. loadedName = "lau68Rocket";
  1879.  
  1880. ordMass = 0.008f;
  1881. ordHardness = 420f;
  1882. warheadType = (float)chosenWHead;
  1883. ordDrag = 0.7f;
  1884. ordMDrag = 0.7f;
  1885. ordADrag = 1f;
  1886. partRadius = 0.015f;
  1887. ordIsRetarded = false;
  1888. ordRDelay = 0f;
  1889. ordRDrag = 0f;
  1890. ordIsAirBurst = false;
  1891. ordBurstAlt = 0.0;
  1892. ordIsClusterBomb = false;
  1893. ordClusterBomblets = 0;
  1894. ordIsTorpedo = false;
  1895. ordIsRocket = true;
  1896. ordRocSize = 1f;
  1897. ordTorpThrust = 1.4f;
  1898. ordTorpRTimer = 500f;
  1899.  
  1900. }
  1901. if (ordType == "hellfireRocket")
  1902. {
  1903. loadedName = "hellfireRocket";
  1904. ordinanceInstance.transform.localScale = new Vector3(2f, 2f, 2f);
  1905. ordMass = 0.085f;
  1906. ordHardness = 415f;
  1907. warheadType = (float)chosenWHead;
  1908. ordDrag = 0.7f;
  1909. ordMDrag = 0.7f;
  1910. ordADrag = 0.9f;
  1911. partRadius = 0.125f;
  1912. ordIsRetarded = false;
  1913. ordRDelay = 0f;
  1914. ordRDrag = 0f;
  1915. ordIsAirBurst = false;
  1916. ordBurstAlt = 0.0;
  1917. ordIsClusterBomb = false;
  1918. ordClusterBomblets = 0;
  1919. ordIsTorpedo = false;
  1920. ordIsRocket = true;
  1921. ordRocSize = 2f;
  1922. ordTorpThrust = 15f;
  1923. ordTorpRTimer = 800f;
  1924.  
  1925. }
  1926.  
  1927.  
  1928. ordinanceInstance.SetActive(true);
  1929.  
  1930. ordinanceInstance.transform.position = hardPoint.position - (hardPoint.up.normalized * partRadius);
  1931. ordinanceInstance.transform.rotation = hardPoint.rotation;
  1932.  
  1933. ordinanceInstance.transform.parent = this.part.transform;
  1934.  
  1935. bombLoaded = true;
  1936. }
  1937. }
  1938. }
  1939.  
  1940. if (ordType == "Nil")
  1941. {
  1942. bombLoaded = false;
  1943. loadedName = "Nil";
  1944.  
  1945. ordMass = 0f;
  1946. ordHardness = 0f;
  1947. warheadType = 0f;
  1948. ordDrag = 0f;
  1949. ordMDrag = 0f;
  1950. ordADrag = 0f;
  1951. partRadius = 0f;
  1952. ordIsRetarded = false;
  1953. ordRDelay = 0f;
  1954. ordRDrag = 0f;
  1955. ordIsAirBurst = false;
  1956. ordBurstAlt = 0;
  1957. ordIsClusterBomb = false;
  1958. ordClusterBomblets = 0;
  1959. ordIsTorpedo = false;
  1960. ordIsRocket = false;
  1961. ordRocSize = 0f;
  1962. ordTorpThrust = 0f;
  1963. ordTorpRTimer = 0f;
  1964.  
  1965.  
  1966. }
  1967.  
  1968.  
  1969.  
  1970.  
  1971. this.part.mass = emptyMass + ordMass;
  1972. this.part.maximum_drag = emptyMDrag + ordMDrag;
  1973. this.part.minimum_drag = emptyDrag + ordDrag;
  1974. this.part.angularDrag = emptyADrag + ordADrag;
  1975.  
  1976. if (isRocketPod && podRockets > 1f)
  1977. {
  1978. this.part.mass = emptyMass + (ordMass * podRockets);
  1979. }
  1980.  
  1981.  
  1982.  
  1983. }
  1984.  
  1985. }
  1986.  
  1987.  
  1988.  
  1989.  
  1990.  
  1991. class IDDropBomb : MonoBehaviour
  1992. {
  1993.  
  1994. public String targetVessel = "None";
  1995.  
  1996. public Transform thrustPoint;
  1997.  
  1998. public GameObject rocketSmokeFX;
  1999.  
  2000. public float maxTorque = 1200f;
  2001.  
  2002. public bool isSafe = true;
  2003.  
  2004. public bool zeroVelOnce = true;
  2005.  
  2006. [KSPField]
  2007. public float timerGoBoom = 150f;
  2008.  
  2009. public float septimer = 0f;
  2010. public bool waitPeriod = true;
  2011.  
  2012. [KSPField]
  2013. public bool isRetarded = false;
  2014.  
  2015. [KSPField]
  2016. public float retardDelay = 1f;
  2017.  
  2018. [KSPField]
  2019. public float retardDrag = 2f;
  2020.  
  2021. [KSPField]
  2022. public bool isClusterBomb = false;
  2023.  
  2024. [KSPField]
  2025. public int clusterBomblets = 16;
  2026.  
  2027. [KSPField]
  2028. public bool isAirBurst = false;
  2029.  
  2030. [KSPField]
  2031. public bool isTorpedo = false;
  2032.  
  2033. public bool splashSet = true;
  2034.  
  2035. public bool tGuided = true;
  2036.  
  2037. public Quaternion headingT;
  2038.  
  2039. [KSPField]
  2040. public bool isRocket = false;
  2041.  
  2042. public float rocketSSS = 0.005f;
  2043.  
  2044. [KSPField]
  2045. public double runDepth = -1.5;
  2046.  
  2047. public Transform holdTorpHeading;
  2048.  
  2049. public float torpedoThrust = 5f;
  2050.  
  2051. [KSPField]
  2052. public double burstAlt = 250.0d;
  2053.  
  2054. public float isWarheadType = 0f;
  2055.  
  2056. public float torpedoLifeTimer = 5000f;
  2057.  
  2058. public float origTLT;
  2059.  
  2060. public float isHardness = 250f;
  2061.  
  2062. private bool oneExplosion = true;
  2063.  
  2064. public double partAltitude = 0.0d;
  2065.  
  2066. private float explosionPower, blastRadius;
  2067.  
  2068. private bool doItOnce = true;
  2069.  
  2070. private bool burstOnce = true;
  2071.  
  2072. public AudioSource soundDrop;
  2073.  
  2074. public Vector3 thisWayUp;
  2075.  
  2076. private float _inertia;
  2077.  
  2078.  
  2079. void Awake()
  2080. {
  2081. if (rigidbody != null)
  2082. {
  2083.  
  2084. _inertia = Mathf.Max(rigidbody.inertiaTensor.x, rigidbody.inertiaTensor.y, rigidbody.inertiaTensor.z);
  2085. }
  2086. }
  2087.  
  2088. public void Start()
  2089. {
  2090. if (isRocket)
  2091. {
  2092. if (thrustPoint == null)
  2093. {
  2094. try
  2095. {
  2096.  
  2097. Transform[] findTP = this.gameObject.GetComponents<Transform>();
  2098. foreach (Transform t in findTP)
  2099. {
  2100. if (t.name.Contains("thrustTransform"))
  2101. {
  2102. thrustPoint = t;
  2103. }
  2104. }
  2105. }
  2106. catch
  2107. {
  2108. print("Problem locating thrustTransform!");
  2109. }
  2110.  
  2111. if (thrustPoint != null)
  2112. {
  2113. print("Found the Rocket Thrustpoint");
  2114. }
  2115. }
  2116. }
  2117.  
  2118. #region Sound effects
  2119. if (!isRocket && septimer == 0f)
  2120. {
  2121. if (!GameDatabase.Instance.ExistsAudioClip("IDSkillfulR1/Sounds/bombDrop")) return;
  2122.  
  2123. soundDrop = this.gameObject.AddComponent<AudioSource>();
  2124.  
  2125.  
  2126. if (soundDrop.audio != null)
  2127. {
  2128.  
  2129. soundDrop.audio.volume = GameSettings.SHIP_VOLUME;
  2130. soundDrop.audio.rolloffMode = AudioRolloffMode.Linear;
  2131. soundDrop.audio.dopplerLevel = 0f;
  2132. soundDrop.audio.panLevel = 1f;
  2133. soundDrop.audio.clip = GameDatabase.Instance.GetAudioClip("IDSkillfulR1/Sounds/bombDrop");
  2134. soundDrop.audio.loop = false;
  2135. soundDrop.audio.playOnAwake = false;
  2136. soundDrop.audio.priority = 2;
  2137. }
  2138. }
  2139.  
  2140. if(isRocket && septimer == 0f)
  2141. {
  2142. if (!GameDatabase.Instance.ExistsAudioClip("IDSkillfulR1/Sounds/IDRocket")) return;
  2143.  
  2144. soundDrop = this.gameObject.AddComponent<AudioSource>();
  2145.  
  2146.  
  2147. if (soundDrop.audio != null)
  2148. {
  2149.  
  2150. soundDrop.audio.volume = GameSettings.SHIP_VOLUME;
  2151. soundDrop.audio.rolloffMode = AudioRolloffMode.Linear;
  2152. soundDrop.audio.dopplerLevel = 0f;
  2153. soundDrop.audio.panLevel = 1f;
  2154. soundDrop.audio.clip = GameDatabase.Instance.GetAudioClip("IDSkillfulR1/Sounds/IDRocket");
  2155. soundDrop.audio.loop = true;
  2156. soundDrop.audio.playOnAwake = false;
  2157. soundDrop.audio.priority = 2;
  2158. }
  2159. }
  2160.  
  2161. #endregion
  2162. }
  2163.  
  2164.  
  2165.  
  2166. public void FixedUpdate()
  2167. {
  2168. if (HighLogic.LoadedSceneIsFlight)
  2169. {
  2170. if (doItOnce == true)
  2171. {
  2172. this.gameObject.SetActive(true);
  2173. setColliderStateInChildren(this.gameObject, true);
  2174.  
  2175. septimer = 0f;
  2176.  
  2177.  
  2178. if (isRocket)
  2179. {
  2180. explosionPower = rigidbody.mass * 100f;
  2181. }
  2182. else
  2183. {
  2184. explosionPower = rigidbody.mass * 500f;
  2185. }
  2186.  
  2187. blastRadius = explosionPower * 0.25f;
  2188. doItOnce = false;
  2189. }
  2190.  
  2191.  
  2192. partAltitude = Vector3.Distance(this.rigidbody.transform.position, FlightGlobals.ActiveVessel.mainBody.position) - (float)FlightGlobals.ActiveVessel.mainBody.Radius;
  2193.  
  2194. thisWayUp = (this.transform.position - FlightGlobals.ActiveVessel.mainBody.position).normalized;
  2195.  
  2196. if (this.partAltitude < -3.0)
  2197. {
  2198.  
  2199. if (splashSet == true)
  2200. {
  2201. //print("Hit the water!");
  2202. FXMonger.Splash(this.transform.position, this.rigidbody.velocity.magnitude * this.rigidbody.mass);
  2203. splashSet = false;
  2204. }
  2205.  
  2206. if (!isTorpedo)
  2207. {
  2208. GameObject fxSplashInstance = new GameObject();
  2209.  
  2210. try
  2211. {
  2212.  
  2213. fxSplashInstance = GameDatabase.Instance.GetModel("IDSkillfulR1/Effects/largeSplash/model");
  2214. }
  2215. catch
  2216. {
  2217. print("Problem locating largeSplash");
  2218. }
  2219.  
  2220. if (fxSplashInstance != null)
  2221. {
  2222.  
  2223. fxSplashInstance.SetActive(true);
  2224. fxSplashInstance.transform.parent = null;
  2225. fxSplashInstance.transform.position = this.transform.position;
  2226. fxSplashInstance.transform.rotation = Quaternion.LookRotation(-thisWayUp.normalized);
  2227.  
  2228. fxSplashInstance.gameObject.layer = 0;
  2229. Destroy(fxSplashInstance, 5f * this.rigidbody.mass);
  2230. }
  2231.  
  2232. Destroy(this.gameObject);
  2233.  
  2234. }
  2235.  
  2236. }
  2237.  
  2238. if (oneExplosion == true)
  2239. {
  2240.  
  2241. septimer += Time.deltaTime;
  2242. isSafe = false;
  2243. if (soundDrop.audio.isPlaying == false && septimer < 2f && this.rigidbody.velocity.magnitude > 3f && !isTorpedo)
  2244. {
  2245. soundDrop.audio.Play();
  2246.  
  2247. }
  2248. if (soundDrop.audio.isPlaying == true && this.rigidbody.velocity.magnitude < 3f)
  2249. {
  2250. soundDrop.audio.Stop();
  2251. }
  2252.  
  2253. if (isRetarded)
  2254. {
  2255. if (retardDelay <= septimer)
  2256. {
  2257. if (this.rigidbody.drag != retardDrag)
  2258. {
  2259. this.rigidbody.drag = retardDrag;
  2260. //print("Retarded Bomb Extended Brakes");
  2261. }
  2262.  
  2263.  
  2264.  
  2265. }
  2266. }
  2267. if (isClusterBomb && !isAirBurst)
  2268. {
  2269. if (isSafe == false && burstOnce == true)
  2270. {
  2271. timerGoBoom--;
  2272.  
  2273. if (timerGoBoom <= 0f)
  2274. {
  2275. this.rigidbody.drag = (float)rndNumber.rndDouble(0.18, 0.5);
  2276.  
  2277. int fragCache = clusterBomblets;
  2278. GameObject[] exFrag = new GameObject[fragCache];
  2279. for (int i = 0; i < exFrag.Length; i++)
  2280. {
  2281. exFrag[i] = GameDatabase.Instance.GetModel("IDSkillfulR1/Parts/IDWW1Bomb/model");
  2282. exFrag[i].SetActive(true);
  2283. exFrag[i].transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);
  2284. exFrag[i].transform.position = this.gameObject.transform.position + UnityEngine.Random.insideUnitSphere * (explosionPower * 0.225f);
  2285.  
  2286. Vector3 randomDirection = new Vector3(rndNumber.rndRoll(-359, 359), rndNumber.rndRoll(-359, 359), rndNumber.rndRoll(-359, 359));
  2287. exFrag[i].transform.Rotate(randomDirection);
  2288.  
  2289. Rigidbody rb = exFrag[i].AddComponent<Rigidbody>();
  2290. rb.detectCollisions = true;
  2291. rb.collisionDetectionMode = CollisionDetectionMode.Continuous;
  2292. rb.mass = (this.rigidbody.mass / clusterBomblets);
  2293. rb.drag = (float)rndNumber.rndDouble(0.001, 0.01);
  2294. rb.velocity = this.rigidbody.velocity * 3f;
  2295.  
  2296. setColliderStateInChildren(exFrag[i], true);
  2297.  
  2298. fragImpact fI = exFrag[i].AddComponent<fragImpact>();
  2299. fI.fragWarheadType = this.isWarheadType;
  2300. fI.fragHardness = this.isHardness;
  2301.  
  2302. Destroy(exFrag[i].gameObject, 300f);
  2303.  
  2304. Destroy(this.gameObject);
  2305. burstOnce = false;
  2306. }
  2307.  
  2308. }
  2309. }
  2310. }
  2311. if (isAirBurst && !isClusterBomb)
  2312. {
  2313. if (partAltitude <= burstAlt && isSafe == false)
  2314. {
  2315. doExplosion();
  2316. doShrapnel(this.gameObject, this.rigidbody.mass, this.rigidbody.velocity, this.explosionPower);
  2317. //print("Airburst has Detonated!");
  2318. }
  2319. }
  2320. if (isTorpedo)
  2321. {
  2322. if (torpedoLifeTimer > 0f)
  2323. {
  2324. if (septimer < 2f && waitPeriod == true)
  2325. {
  2326. headingT = holdTorpHeading.rotation;
  2327.  
  2328. waitPeriod = false;
  2329.  
  2330. }
  2331.  
  2332.  
  2333. if (tGuided == true && waitPeriod == false)
  2334. {
  2335. this.gameObject.transform.rotation = headingT;
  2336. }
  2337.  
  2338. torpedoLifeTimer--;
  2339.  
  2340. if(partAltitude < 0.0d)
  2341. {
  2342. this.rigidbody.AddForceAtPosition(this.gameObject.transform.forward * torpedoThrust, this.transform.position);
  2343.  
  2344. }
  2345.  
  2346. if (partAltitude < runDepth)
  2347. {
  2348. if (this.rigidbody.useGravity == true && zeroVelOnce == true)
  2349. {
  2350. this.rigidbody.velocity = Vector3.zero;
  2351. zeroVelOnce = false;
  2352. }
  2353. this.rigidbody.useGravity = false;
  2354.  
  2355. if (partAltitude < -1.85)
  2356. {
  2357. this.rigidbody.AddForceAtPosition(thisWayUp.normalized * 0.285f, this.transform.position);
  2358. }
  2359.  
  2360. }
  2361. if (partAltitude > -0.625d)
  2362. {
  2363. this.rigidbody.useGravity = true;
  2364. }
  2365.  
  2366. if (torpedoLifeTimer <= 0f)
  2367. {
  2368. ScreenMessages.PostScreenMessage(new ScreenMessage("Torpedo ran out of fuel!", 4f, ScreenMessageStyle.UPPER_CENTER));
  2369.  
  2370. Destroy(this.gameObject, 0.25f);
  2371. }
  2372. }
  2373.  
  2374. }
  2375. if (isRocket)
  2376. {
  2377.  
  2378. if (rocketSmokeFX == null && septimer < 2f)
  2379. {
  2380. try
  2381. {
  2382.  
  2383. rocketSmokeFX = GameDatabase.Instance.GetModel("IDSkillfulR1/Effects/rocketSmoke/model");
  2384. }
  2385. catch
  2386. {
  2387. print("Problem locating rocketSmoke");
  2388. }
  2389.  
  2390. if (rocketSmokeFX != null)
  2391. {
  2392.  
  2393. rocketSmokeFX.SetActive(true);
  2394. rocketSmokeFX.transform.parent = this.gameObject.transform;
  2395. if (thrustPoint != null)
  2396. {
  2397. rocketSmokeFX.transform.position = thrustPoint.position;
  2398. }
  2399. else
  2400. {
  2401. rocketSmokeFX.transform.position = this.transform.position;
  2402. }
  2403.  
  2404. rocketSmokeFX.gameObject.layer = 0;
  2405. origTLT = torpedoLifeTimer;
  2406. Destroy(rocketSmokeFX, torpedoLifeTimer * 0.05f);
  2407. }
  2408. }
  2409.  
  2410. if (torpedoLifeTimer > 0f && partAltitude > 0.0)
  2411. {
  2412. torpedoLifeTimer--;
  2413.  
  2414. if (septimer < (origTLT * 0.045f))
  2415. {
  2416. this.rigidbody.AddForceAtPosition(this.transform.forward * (torpedoThrust * rndNumber.rndFloat(0.85f, 1.0f)), this.transform.position);
  2417.  
  2418. if (septimer < 2f && waitPeriod == true)
  2419. {
  2420. headingT = holdTorpHeading.rotation;
  2421. this.gameObject.transform.rotation = headingT;
  2422.  
  2423. }
  2424. else if (septimer >= 2f && waitPeriod == true)
  2425. {
  2426. waitPeriod = false;
  2427. }
  2428.  
  2429.  
  2430. if (FlightGlobals.fetch.vesselTargetMode != FlightGlobals.VesselTargetModes.None && tGuided != false && waitPeriod == false)
  2431. {
  2432. ITargetable target = FlightGlobals.fetch.VesselTarget;
  2433.  
  2434. Vector3 targetDirection = target.GetTransform().position - this.transform.position;
  2435.  
  2436.  
  2437. Vector3 rotateTarget;
  2438. if (targetDirection.sqrMagnitude > float.Epsilon)
  2439. rotateTarget = targetDirection.normalized;
  2440. else
  2441. rotateTarget = transform.forward;
  2442.  
  2443.  
  2444. var dot = Vector3.Dot(transform.forward, rotateTarget);
  2445. if (1 - dot > float.Epsilon)
  2446. {
  2447. Vector3 rotationAxis;
  2448. float angle;
  2449.  
  2450.  
  2451. if (dot + 1 < float.Epsilon)
  2452. {
  2453. rotationAxis = Vector3.up;
  2454. angle = Mathf.PI;
  2455. }
  2456. else
  2457. {
  2458. rotationAxis = Vector3.Cross(transform.forward, rotateTarget);
  2459. angle = Mathf.Asin(Mathf.Min(1, rotationAxis.magnitude));
  2460. rotationAxis.Normalize();
  2461.  
  2462.  
  2463. if (dot < 0)
  2464. angle = Mathf.PI - angle;
  2465. }
  2466.  
  2467.  
  2468. var desiredSpeed = Mathf.Sqrt(0.66f * angle * maxTorque / _inertia);
  2469. var desiredVelocity = rotationAxis * desiredSpeed;
  2470. var deltaVelocity = desiredVelocity - rigidbody.angularVelocity;
  2471.  
  2472. if (deltaVelocity.sqrMagnitude > float.Epsilon)
  2473. {
  2474.  
  2475. var acceleration = deltaVelocity / Time.fixedDeltaTime;
  2476. var torque = acceleration * _inertia;
  2477.  
  2478. this.rigidbody.AddTorque(Vector3.ClampMagnitude(torque, maxTorque));
  2479. }
  2480. }
  2481.  
  2482.  
  2483.  
  2484. }
  2485. else
  2486. {
  2487. if (tGuided == true && waitPeriod == false)
  2488. {
  2489. this.gameObject.transform.rotation = headingT;
  2490. this.rigidbody.useGravity = true;
  2491. tGuided = false;
  2492. }
  2493. this.gameObject.transform.rotation = headingT;
  2494. }
  2495.  
  2496. }
  2497.  
  2498. if (torpedoLifeTimer <= 0f || this.rigidbody.velocity.magnitude < 40f && septimer > 5f)
  2499. {
  2500. FXMonger.Explode(FlightGlobals.ActiveVessel.rootPart, this.transform.position, this.rigidbody.mass * 100f);
  2501. Destroy(this.gameObject, 0.1f);
  2502. }
  2503. }
  2504.  
  2505. }
  2506.  
  2507.  
  2508.  
  2509. }
  2510.  
  2511. }
  2512.  
  2513.  
  2514. }
  2515.  
  2516. public static void doShrapnel(GameObject thisBomb, float bombMass, Vector3 bombSpeed, float explodePower)
  2517. {
  2518. int shrapLimit = 10;
  2519. #region Shrapnel Limit
  2520. if (bombMass < 0.25f)
  2521. {
  2522. shrapLimit = 10;
  2523. }
  2524. if (bombMass >= 0.25f && bombMass < 0.5f)
  2525. {
  2526. shrapLimit = rndNumber.rndRoll(10, 20);
  2527. }
  2528. if (bombMass >= 0.5f && bombMass < 1f)
  2529. {
  2530. shrapLimit = rndNumber.rndRoll(15, 30);
  2531. }
  2532. if (bombMass >= 1f && bombMass < 4f)
  2533. {
  2534. shrapLimit = rndNumber.rndRoll(20, 40);
  2535. }
  2536. if (bombMass >= 4f && bombMass < 10f)
  2537. {
  2538. shrapLimit = rndNumber.rndRoll(30, 60);
  2539. }
  2540. #endregion
  2541. int shrapnel = rndNumber.rndRoll(3, shrapLimit);
  2542.  
  2543. int fragCache = shrapnel;
  2544. GameObject[] exFrag = new GameObject[fragCache];
  2545. for (int i = 0; i < exFrag.Length; i++)
  2546. {
  2547. exFrag[i] = GameObject.CreatePrimitive(PrimitiveType.Cube);
  2548. exFrag[i].SetActive(true);
  2549. exFrag[i].renderer.enabled = false;
  2550. exFrag[i].transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
  2551. exFrag[i].transform.position = thisBomb.transform.position;
  2552. exFrag[i].transform.rotation = UnityEngine.Random.rotationUniform;
  2553. Rigidbody rb = exFrag[i].AddComponent<Rigidbody>();
  2554. setColliderStateInChildren(exFrag[i], true);
  2555. rb.detectCollisions = true;
  2556. rb.collisionDetectionMode = CollisionDetectionMode.Continuous;
  2557. rb.mass = (bombMass / shrapnel);
  2558. rb.drag = rndNumber.rndFloat(0.1f, 0.25f);
  2559.  
  2560. fragImpact fI = exFrag[i].AddComponent<fragImpact>();
  2561. fI.fragWarheadType = 0f;
  2562. fI.fragHardness = 320f;
  2563.  
  2564. rb.velocity = exFrag[i].transform.forward * (explodePower * (rndNumber.rndFloat(0.5f, 1.5f)));
  2565.  
  2566. Destroy(exFrag[i].gameObject, 3f);
  2567.  
  2568. }
  2569. }
  2570.  
  2571. public static void setColliderStateInChildren(GameObject rootObject, bool isTrigger)
  2572. {
  2573.  
  2574. Collider[] colliders = rootObject.GetComponentsInChildren<Collider>(true);
  2575. for (int i = 0; i < colliders.Length; i++)
  2576. {
  2577. colliders[i].isTrigger = isTrigger;
  2578. colliders[i].enabled = true;
  2579.  
  2580.  
  2581. }
  2582. }
  2583.  
  2584. private void doExplosion()
  2585. {
  2586. oneExplosion = false;
  2587.  
  2588. GameObject explosion = Part.Instantiate(UnityEngine.Resources.Load("Effects/fx_exhaustSparks_yellow")) as GameObject;
  2589. explosion.transform.localEulerAngles = Vector3.zero;
  2590. explosion.transform.localPosition = new Vector3(0, 0, 0);
  2591. explosion.transform.position = this.transform.position;
  2592. ParticleEmitter emitter = explosion.particleEmitter;
  2593. emitter.emit = false;
  2594. emitter.minSize = 5f;
  2595. emitter.maxSize = blastRadius * 0.2f;
  2596. emitter.minEnergy = 4f;
  2597. emitter.maxEnergy = 6f;
  2598. emitter.minEmission = 14f;
  2599. emitter.maxEmission = 20f;
  2600. emitter.rndVelocity = Vector3.one * 0.01f;
  2601. emitter.localVelocity = Vector3.zero;
  2602. emitter.useWorldSpace = true;
  2603. emitter.renderer.castShadows = true;
  2604. emitter.renderer.receiveShadows = true;
  2605.  
  2606. ParticleAnimator emitterAnimator = emitter.GetComponent<ParticleAnimator>();
  2607. emitterAnimator.sizeGrow = -0.75f;
  2608. emitterAnimator.particleEmitter.maxSize = 0.45f;
  2609. Color[] emitterColors = emitterAnimator.colorAnimation;
  2610. emitterColors[0] = new Color(1f, 1f, 1f, 0.82f);
  2611. emitterColors[1] = new Color(1f, 0.25f, 0.25f, 0.37f);
  2612. emitterColors[2] = new Color(0.25f, 0.3f, 0f, 0.5f);
  2613. emitterColors[3] = new Color(0.9f, 0.9f, 0.9f, 0.66f);
  2614. emitterColors[4] = new Color(1f, 1f, 1f, 0.05f);
  2615. emitterAnimator.colorAnimation = emitterColors;
  2616. emitter.Emit(30);
  2617.  
  2618. FXMonger.Explode(FlightGlobals.ActiveVessel.rootPart, this.transform.position, 0.9f);
  2619. //print("Bomb has detonated with a force of " + explosionPower);
  2620.  
  2621.  
  2622.  
  2623.  
  2624. }
  2625.  
  2626. public void OnTriggerEnter(Collider Collision)
  2627. {
  2628. if (Collision.gameObject.layer == 15)
  2629. {
  2630.  
  2631. //print("hit the ground or a building, warhead is: " + isWarheadType);
  2632. if (isWarheadType == 1f || isWarheadType == 2f)
  2633. {
  2634. FXMonger.Explode(FlightGlobals.ActiveVessel.rootPart, this.transform.position, this.rigidbody.mass);
  2635. }
  2636. if (isWarheadType == 2f)
  2637. {
  2638. //print("this is an Incendiary hit!");
  2639.  
  2640. GameObject fxFireInstance = new GameObject();
  2641.  
  2642. try
  2643. {
  2644.  
  2645. fxFireInstance = GameDatabase.Instance.GetModel("IDSkillfulR1/Effects/largeGFire/model");
  2646. }
  2647. catch
  2648. {
  2649. print("Problem locating fireFX");
  2650. }
  2651.  
  2652. if (fxFireInstance != null)
  2653. {
  2654. float fireTemp = 100f;
  2655. //print("Setting fx active");
  2656. fxFireInstance.SetActive(true);
  2657. fxFireInstance.transform.parent = null;
  2658. fxFireInstance.transform.position = this.transform.position;
  2659. fxFireInstance.gameObject.layer = 0;
  2660. if (isRocket)
  2661. {
  2662. fireTemp = 50f;
  2663. }
  2664. terrainBurner tB = fxFireInstance.AddComponent<terrainBurner>();
  2665. tB.throwsHeat = fireTemp;
  2666. tB.heatRange = this.rigidbody.mass * 30f;
  2667.  
  2668. Destroy(fxFireInstance, 300f * (float)rndNumber.rndDouble(0.75, 2.5));
  2669. }
  2670.  
  2671.  
  2672. }
  2673.  
  2674. terrainHit();
  2675.  
  2676. }
  2677. }
  2678.  
  2679.  
  2680.  
  2681. public void terrainHit()
  2682. {
  2683.  
  2684.  
  2685. GameObject explosion = Part.Instantiate(UnityEngine.Resources.Load("Effects/fx_exhaustSparks_yellow")) as GameObject;
  2686. explosion.transform.localEulerAngles = Vector3.zero;
  2687. explosion.transform.localPosition = new Vector3(0, 0, 0);
  2688. explosion.transform.position = this.transform.position;
  2689. ParticleEmitter emitter = explosion.particleEmitter;
  2690. emitter.emit = false;
  2691. emitter.minSize = (this.rigidbody.mass * 0.5f) + 0.35f;
  2692. emitter.maxSize = (this.rigidbody.mass * 2f) + 1f;
  2693. emitter.minEnergy = (this.rigidbody.mass * (this.rigidbody.velocity.magnitude * 0.01f)) + 1.2f;
  2694. emitter.maxEnergy = (this.rigidbody.mass * (this.rigidbody.velocity.magnitude * 0.01f)) + 1.5f;
  2695. emitter.rndVelocity = Vector3.one * (float)rndNumber.rndDouble(0.01, 1.0);
  2696. emitter.localVelocity = Vector3.zero;
  2697. emitter.useWorldSpace = true;
  2698. ParticleAnimator emitterAnimator = emitter.GetComponent<ParticleAnimator>();
  2699. emitterAnimator.sizeGrow = 0.0045f;
  2700. Color[] emitterColors = emitterAnimator.colorAnimation;
  2701. emitterColors[0] = new Color(0.5f, 0.45f, 0.18f, 0.95f);
  2702. emitterColors[1] = new Color(0.8f, 0.8f, 0.8f, 1f);
  2703. emitterColors[2] = new Color(0.85f, 0.1f, 0.1f, 0.7f);
  2704. emitterColors[3] = new Color(0.5f, 0.5f, 0.5f, 0.5f);
  2705. emitterColors[4] = new Color(0f, 0f, 0f, 0.25f);
  2706. emitterAnimator.colorAnimation = emitterColors;
  2707.  
  2708. emitter.Emit(8);
  2709.  
  2710. if (!isClusterBomb && isWarheadType == 1f)
  2711. {
  2712.  
  2713. foreach (Vessel v in FlightGlobals.Vessels)
  2714. {
  2715. float blastDistance = Vector3.Distance(v.transform.position, this.transform.position);
  2716. if (blastDistance < blastRadius)
  2717. {
  2718. try
  2719. {
  2720. v.GoOffRails();
  2721. }
  2722. catch
  2723. {
  2724. print("Something is wrong with making the vessel offrails");
  2725. }
  2726.  
  2727. FXMonger.Explode(v.rootPart, v.transform.position, 0.9f / blastDistance);
  2728.  
  2729. v.rigidbody.AddForceAtPosition(Vector3.forward * (explosionPower / (blastDistance * 0.25f)), v.transform.position, ForceMode.Impulse);
  2730.  
  2731. }
  2732. }
  2733.  
  2734. doShrapnel(this.gameObject, this.rigidbody.mass, this.rigidbody.velocity, explosionPower);
  2735.  
  2736. }
  2737.  
  2738.  
  2739. Destroy(this.gameObject);
  2740.  
  2741. }
  2742.  
  2743. }
  2744.  
  2745. public class rndNumber
  2746. {
  2747.  
  2748. public static System.Random rnd = new System.Random();
  2749. public static int rndRoll(int min, int max)
  2750. {
  2751. return rnd.Next(min, max);
  2752. }
  2753.  
  2754. public static System.Random rnd2 = new System.Random();
  2755. public static double rndDouble(double min, double max)
  2756. {
  2757. return rnd2.NextDouble();
  2758. }
  2759. public static System.Random rnd3 = new System.Random();
  2760. public static float rndFloat(float min, float max)
  2761. {
  2762. return (float)rnd3.NextDouble();
  2763. }
  2764.  
  2765. }
  2766.  
  2767. public class terrainBurner : MonoBehaviour
  2768. {
  2769. public float throwsHeat = 100f;
  2770. public float heatRange = 30f;
  2771.  
  2772. public void FixedUpdate()
  2773. {
  2774. foreach (Vessel v in FlightGlobals.Vessels)
  2775. {
  2776. if (v.isEVA == false)
  2777. {
  2778.  
  2779. foreach (Part p in v.Parts)
  2780. {
  2781. float blastDistance = Vector3.Distance(p.transform.position, this.transform.position);
  2782. if (blastDistance < 1f)
  2783. {
  2784. blastDistance = 1f;
  2785. }
  2786. if (blastDistance < heatRange)
  2787. {
  2788. p.temperature += (throwsHeat * (heatRange / blastDistance)) * Time.deltaTime;
  2789. }
  2790. }
  2791.  
  2792. }
  2793. }
  2794.  
  2795. }
  2796.  
  2797. }
  2798.  
  2799.  
  2800. public class fragImpact : MonoBehaviour
  2801. {
  2802.  
  2803. public double partAltitude;
  2804. public float fragHardness = 250f;
  2805. public float fragWarheadType = 1f;
  2806.  
  2807. public void FixedUpdate()
  2808. {
  2809. partAltitude = Vector3.Distance(this.rigidbody.transform.position, FlightGlobals.ActiveVessel.mainBody.position) - (float)FlightGlobals.ActiveVessel.mainBody.Radius;
  2810.  
  2811. if (this.partAltitude < -3.0)
  2812. {
  2813.  
  2814. FXMonger.Splash(this.transform.position, this.rigidbody.velocity.magnitude * this.rigidbody.mass);
  2815. terrainHit();
  2816.  
  2817. }
  2818. }
  2819.  
  2820. public void OnTriggerEnter(Collider Collision)
  2821. {
  2822. if (Collision.gameObject.layer == 15)
  2823. {
  2824.  
  2825. if (fragWarheadType == 1f) FXMonger.Explode(FlightGlobals.ActiveVessel.rootPart, this.transform.position, this.rigidbody.mass);
  2826. terrainHit();
  2827.  
  2828. }
  2829. }
  2830.  
  2831. public void terrainHit()
  2832. {
  2833.  
  2834.  
  2835. GameObject explosion = Part.Instantiate(UnityEngine.Resources.Load("Effects/fx_exhaustSparks_yellow")) as GameObject;
  2836. explosion.transform.localEulerAngles = Vector3.zero;
  2837. explosion.transform.localPosition = new Vector3(0, 0, 0);
  2838. explosion.transform.position = this.transform.position;
  2839. ParticleEmitter emitter = explosion.particleEmitter;
  2840. emitter.emit = false;
  2841. emitter.minSize = (this.rigidbody.mass * 0.5f) + 0.35f;
  2842. emitter.maxSize = (this.rigidbody.mass * 2f) + 1f;
  2843. emitter.minEnergy = (this.rigidbody.mass * (this.rigidbody.velocity.magnitude * 0.01f)) + 1.2f;
  2844. emitter.maxEnergy = (this.rigidbody.mass * (this.rigidbody.velocity.magnitude * 0.01f)) + 1.5f;
  2845. emitter.rndVelocity = Vector3.one * (float)rndNumber.rndDouble(0.01, 1.0);
  2846. emitter.localVelocity = Vector3.zero;
  2847. emitter.useWorldSpace = true;
  2848. ParticleAnimator emitterAnimator = emitter.GetComponent<ParticleAnimator>();
  2849. emitterAnimator.sizeGrow = 0.0045f;
  2850. Color[] emitterColors = emitterAnimator.colorAnimation;
  2851. emitterColors[0] = new Color(0.5f, 0.45f, 0.18f, 0.95f);
  2852. emitterColors[1] = new Color(0.8f, 0.8f, 0.8f, 1f);
  2853. emitterColors[2] = new Color(0.85f, 0.1f, 0.1f, 0.7f);
  2854. emitterColors[3] = new Color(0.5f, 0.5f, 0.5f, 0.5f);
  2855. emitterColors[4] = new Color(0f, 0f, 0f, 0.25f);
  2856. emitterAnimator.colorAnimation = emitterColors;
  2857.  
  2858. emitter.Emit(8);
  2859.  
  2860.  
  2861.  
  2862. Destroy(this.gameObject);
  2863. }
  2864.  
  2865.  
  2866. }
  2867.  
  2868. ************************************************************************ordnancepart
  2869.  
  2870. using System;
  2871. using System.Collections.Generic;
  2872. using System.Text;
  2873. using System.Threading.Tasks;
  2874. using UnityEngine;
  2875. using System.Linq;
  2876.  
  2877. public class targetPart : PartModule
  2878. {
  2879. [KSPField(isPersistant = true)]
  2880. public float targetStructure = 0f;
  2881.  
  2882. [KSPField]
  2883. public float targetHardness = 150f;
  2884.  
  2885. [KSPField]
  2886. public float targetNotVoid = 1f;
  2887.  
  2888. [KSPField]
  2889. public float targetType = 2f;
  2890.  
  2891. [KSPField(guiActive = true, guiName = "Current Structure", isPersistant = true)]
  2892. public float currentPartStructure;
  2893.  
  2894. [KSPField(guiActive = true, guiName = "Current Temperature", isPersistant = false)]
  2895. public float currentPartTemp;
  2896.  
  2897. [KSPField]
  2898. public string objectType = "none";
  2899.  
  2900. public float heatProduction = 1050f;
  2901.  
  2902. [KSPField(isPersistant = true)]
  2903. public float currentMass;
  2904.  
  2905. [KSPField(isPersistant = true)]
  2906. private float originalMass;
  2907.  
  2908. [KSPField(isPersistant = true)]
  2909. private bool hasBeenHit = false;
  2910.  
  2911. [KSPField(isPersistant = true)]
  2912. public bool torpWaterlinePenetration = false;
  2913.  
  2914. [KSPField(isPersistant = true)]
  2915. public bool isSinking = false;
  2916.  
  2917. [KSPField(isPersistant = true)]
  2918. public float vesselOriginalTotalMass;
  2919.  
  2920. [KSPField(isPersistant = true)]
  2921. public float targetPartVolume = 0f;
  2922.  
  2923. [KSPField(isPersistant = true)]
  2924. public bool targetBurnedOut;
  2925.  
  2926. [KSPField(isPersistant = true)]
  2927. public float countedTargetParts;
  2928.  
  2929. [KSPField(isPersistant = true)]
  2930. public float checkCritSink;
  2931.  
  2932. [KSPField(guiActive = true, guiName = "Part Burning", isPersistant = true)]
  2933. public bool targetIsBurning = false;
  2934.  
  2935. [KSPField(isPersistant = true)]
  2936. public bool weKnowOrigMass = false;
  2937.  
  2938. public float explosionPower;
  2939. public bool bombJustExploded = false;
  2940.  
  2941.  
  2942. private float structHitLoss;
  2943. public int fireFlicker;
  2944. public float timeFireFlicker;
  2945.  
  2946. public float fireSpreadModifier = 2.5f;
  2947.  
  2948. public GameObject fxFireInstance;
  2949. public Vector3 thisWayUp;
  2950.  
  2951.  
  2952. //*************************************
  2953. public float projPenBaseline = 1f;
  2954. public float projPenetrate = 0f;
  2955. public float projHardness;
  2956. public float impactEnergy;
  2957. public float penetrateChance;
  2958. public float projectileMass;
  2959. public float projectileVelocity;
  2960.  
  2961. public bool fuelLeak = false;
  2962. public double fLeakRate = 0.0;
  2963. public double leakToLevel = 1.0;
  2964.  
  2965. [KSPField(isPersistant = true)]
  2966. public float wingOriginalSurfaceArea;
  2967.  
  2968. public float dmgCalcScaler = 1f;
  2969.  
  2970. //***********************************************
  2971. private List<targetPart> targList;
  2972. private List<targetPart> countList;
  2973.  
  2974. public bool thisPartRestored = false;
  2975.  
  2976. //**********************************************
  2977. private List<targetPart> sinkList;
  2978.  
  2979. public int targToSinkNumber;
  2980. public bool setConditionS = false;
  2981. public float sinkCheckTime;
  2982. public float countSTimer;
  2983. public float sinkStartTime;
  2984. //*******************
  2985.  
  2986. public bool setConditionF = false;
  2987. public float fireDieTimer = 120f;
  2988. public float fireStartTimer = 30f;
  2989. public float fireTicker = 0f;
  2990.  
  2991. //************************************************************************************
  2992. [KSPField(guiActive = false, guiName = "Part Volume", isPersistant = true)]
  2993. public float thisPartMeshVolume;
  2994.  
  2995. public float SignedVolumeOfTriangle(Vector3 p1, Vector3 p2, Vector3 p3)
  2996. {
  2997. float v321 = p3.x * p2.y * p1.z;
  2998. float v231 = p2.x * p3.y * p1.z;
  2999. float v312 = p3.x * p1.y * p2.z;
  3000. float v132 = p1.x * p3.y * p2.z;
  3001. float v213 = p2.x * p1.y * p3.z;
  3002. float v123 = p1.x * p2.y * p3.z;
  3003.  
  3004. return (1.0f / 6.0f) * (-v321 + v231 + v312 - v132 - v213 + v123);
  3005. }
  3006.  
  3007. float VolumeOfMesh(Mesh mesh)
  3008. {
  3009. float volume = 0;
  3010.  
  3011. Vector3[] vertices = mesh.vertices;
  3012. int[] triangles = mesh.triangles;
  3013.  
  3014. for (int i = 0; i < mesh.triangles.Length; i += 3)
  3015. {
  3016. Vector3 p1 = vertices[triangles[i + 0]];
  3017. Vector3 p2 = vertices[triangles[i + 1]];
  3018. Vector3 p3 = vertices[triangles[i + 2]];
  3019. volume += SignedVolumeOfTriangle(p1, p2, p3);
  3020. }
  3021.  
  3022. return Mathf.Abs(volume);
  3023. }
  3024.  
  3025. //***************************************
  3026. public float warheadModifier = 0;
  3027. public bool wasHitByIncindiary = false;
  3028. public bool hitIsTorpedo = false;
  3029.  
  3030. //**************************************
  3031.  
  3032. public GameObject bulletHoleInstance;
  3033.  
  3034. public float vesselMass = 0f;
  3035.  
  3036. public AudioSource bulletHitM1, bulletHitM2;
  3037.  
  3038. public fragImpact fragImpactHandler;
  3039.  
  3040. public bool kerbalFightsFire = false;
  3041.  
  3042. //*******************************
  3043.  
  3044. public Rigidbody thisBRB;
  3045.  
  3046. public Vector3 thisTargetPOS;
  3047.  
  3048. public Transform foundDmgState;
  3049.  
  3050. public string useFireFX = "IDSkillfulR1/Effects/smallFire/model";
  3051.  
  3052. public bool firstRun = true;
  3053.  
  3054. #region fix variables
  3055. public bool fixOngoing = false;
  3056. public string jobName = "nil";
  3057. public float fixTime = 0f;
  3058. public float startTime = 0f;
  3059. public bool takeResOnce = false;
  3060. public float doneTime = 0f;
  3061. public float ourKerbalsStupid = 0f;
  3062. public float ourKerbalCourage = 0f;
  3063. public bool ourKerbalIsBadass = false;
  3064. public string lastKerbalName = "";
  3065.  
  3066. #endregion
  3067.  
  3068. public bool setCSinCNew = false;
  3069.  
  3070. [KSPEvent(active = true, guiName = "Fight Fire", guiActiveUnfocused = true, externalToEVAOnly = true, guiActive = false, unfocusedRange = 8f)]
  3071. public void fixFire()
  3072. {
  3073. bool allowFireFight = false;
  3074. foreach (Part p in this.vessel.Parts)
  3075. {
  3076. targetPart tP = p.GetComponent<targetPart>();
  3077. if (tP != null && tP.targetIsBurning == true)
  3078. {
  3079. allowFireFight = true;
  3080. }
  3081. }
  3082.  
  3083. if (kerbalFightsFire == false && allowFireFight == true)
  3084. {
  3085. kerbalFightsFire = true;
  3086. ScreenMessages.PostScreenMessage(new ScreenMessage("Kerbal fighting any fires! ...moving will abort job!...", 5f, ScreenMessageStyle.UPPER_CENTER));
  3087. }
  3088. else
  3089. {
  3090. kerbalFightsFire = false;
  3091. }
  3092. }
  3093.  
  3094. [KSPEvent(active = true, guiName = "Fix Damage", guiActiveUnfocused = true, externalToEVAOnly = true, guiActive = false, unfocusedRange = 4f)]
  3095. public void fixState()
  3096. {
  3097. bool allowJob = false;
  3098. foreach (Part p in this.vessel.Parts)
  3099. {
  3100. relayIFF rI = p.GetComponent<relayIFF>();
  3101. if (rI != null)
  3102. {
  3103. allowJob = true;
  3104. }
  3105. }
  3106.  
  3107. if (fixOngoing == false && allowJob == true)
  3108. {
  3109. jobName = "Fix";
  3110. fixTime = 60f * (1f + ourKerbalsStupid);
  3111. startTime = Time.time;
  3112. //print(startTime + " is the time the job started. ET to complete: " + fixTime);
  3113. ScreenMessages.PostScreenMessage(new ScreenMessage("This might take a while! Please be patient! ...and quiet!...", fixTime, ScreenMessageStyle.UPPER_CENTER));
  3114. fixOngoing = true;
  3115. takeResOnce = true;
  3116. doneTime = fixTime + startTime;
  3117.  
  3118. }
  3119.  
  3120. }
  3121.  
  3122.  
  3123. public void Start()
  3124. {
  3125.  
  3126. try
  3127. {
  3128. foundDmgState = this.part.FindModelTransform("dmgState");
  3129. }
  3130. catch
  3131. {
  3132. print("Part has no Damage Model - no swap will happen");
  3133. }
  3134.  
  3135. if (foundDmgState != null)
  3136. {
  3137. if (currentPartStructure > 0f)
  3138. {
  3139. Transform affectDmgState = this.part.FindModelTransform("dmgState");
  3140. affectDmgState.GetComponent<MeshRenderer>().enabled = false;
  3141. Transform affectCleanState = this.part.FindModelTransform("targetPart");
  3142. affectCleanState.GetComponent<MeshRenderer>().enabled = true;
  3143. }
  3144. if (currentPartStructure == 0f)
  3145. {
  3146. Transform affectDmgState = this.part.FindModelTransform("dmgState");
  3147. affectDmgState.GetComponent<MeshRenderer>().enabled = true;
  3148. Transform affectCleanState = this.part.FindModelTransform("targetPart");
  3149. affectCleanState.GetComponent<MeshRenderer>().enabled = false;
  3150. }
  3151. if (!HighLogic.LoadedSceneIsFlight)
  3152. {
  3153. Transform affectDmgState = this.part.FindModelTransform("dmgState");
  3154. affectDmgState.GetComponent<MeshRenderer>().enabled = false;
  3155. Transform affectCleanState = this.part.FindModelTransform("targetPart");
  3156. affectCleanState.GetComponent<MeshRenderer>().enabled = true;
  3157.  
  3158.  
  3159. }
  3160. }
  3161.  
  3162. #region Bullet Hit Sounds
  3163.  
  3164. if (!GameDatabase.Instance.ExistsAudioClip("IDSkillfulR1/Sounds/IDhitM1") || !GameDatabase.Instance.ExistsAudioClip("IDSkillfulR1/Sounds/IDhitM2")) return;
  3165.  
  3166. bulletHitM1 = this.gameObject.AddComponent<AudioSource>();
  3167. bulletHitM2 = this.gameObject.AddComponent<AudioSource>();
  3168.  
  3169. bulletHitM1.audio.clip = GameDatabase.Instance.GetAudioClip("IDSkillfulR1/Sounds/IDhitM1");
  3170. bulletHitM2.audio.clip = GameDatabase.Instance.GetAudioClip("IDSkillfulR1/Sounds/IDhitM2");
  3171.  
  3172. if (bulletHitM1 != null)
  3173. {
  3174. bulletHitM1.audio.volume = GameSettings.SHIP_VOLUME;
  3175. bulletHitM1.audio.rolloffMode = AudioRolloffMode.Linear;
  3176. bulletHitM1.audio.dopplerLevel = 0f;
  3177. bulletHitM1.audio.panLevel = 1f;
  3178. bulletHitM1.audio.loop = false;
  3179. bulletHitM1.audio.playOnAwake = false;
  3180. bulletHitM1.audio.priority = 3;
  3181. }
  3182.  
  3183. if (bulletHitM2 != null)
  3184. {
  3185. bulletHitM2.audio.volume = GameSettings.SHIP_VOLUME;
  3186. bulletHitM2.audio.rolloffMode = AudioRolloffMode.Linear;
  3187. bulletHitM2.audio.dopplerLevel = 0f;
  3188. bulletHitM2.audio.panLevel = 1f;
  3189. bulletHitM2.audio.loop = false;
  3190. bulletHitM2.audio.playOnAwake = false;
  3191. bulletHitM2.audio.priority = 3;
  3192.  
  3193. }
  3194.  
  3195.  
  3196.  
  3197.  
  3198. #endregion
  3199.  
  3200.  
  3201.  
  3202.  
  3203.  
  3204. }
  3205.  
  3206.  
  3207.  
  3208. public void FixedUpdate()
  3209. {
  3210. if (HighLogic.LoadedSceneIsFlight)
  3211. {
  3212. if (FlightGlobals.ActiveVessel.isEVA == true)
  3213. {
  3214. if (this.vessel.horizontalSrfSpeed > 0.2f)
  3215. {
  3216. kerbalFightsFire = false;
  3217. }
  3218.  
  3219. relayIFF rI = this.GetComponent<relayIFF>();
  3220. if (rI != null)
  3221. {
  3222. ProtoCrewMember getStats = FlightGlobals.ActiveVessel.GetVesselCrew().FirstOrDefault();
  3223. if (lastKerbalName != getStats.name)
  3224. {
  3225. checkKerbal();
  3226. }
  3227. }
  3228. }
  3229.  
  3230. if (fixOngoing == true && doneTime > Time.time && (this.part.transform.position.magnitude - FlightGlobals.ActiveVessel.transform.position.magnitude) > 4f || fixOngoing == true && doneTime > Time.time && FlightGlobals.ActiveVessel.isEVA == false)
  3231. {
  3232. ScreenMessages.PostScreenMessage(new ScreenMessage("You botched the job! Please stay within 4m of the job site, do not switch away or enter any vessel.", 10f, ScreenMessageStyle.UPPER_CENTER));
  3233. fixOngoing = false;
  3234. jobName = "nil";
  3235. }
  3236.  
  3237. if (fixOngoing == true && doneTime < Time.time && jobName == "Fix")
  3238. {
  3239. //print("Inside the condition...");
  3240. bool foundParts = false;
  3241.  
  3242. List<Collider> nearestColliders = new List<Collider>(Physics.OverlapSphere(this.transform.position, 40f));
  3243. foreach (Collider col in nearestColliders)
  3244. {
  3245.  
  3246. if (!col.attachedRigidbody)
  3247. {
  3248.  
  3249. continue;
  3250. }
  3251.  
  3252. Part p = col.attachedRigidbody.GetComponent<Part>();
  3253. if (!p)
  3254. {
  3255.  
  3256. continue;
  3257. }
  3258.  
  3259.  
  3260. PartResourceList resourceList = p.Resources;
  3261. foreach (PartResource resource in resourceList)
  3262. {
  3263. if (resource.resourceName == "SpareParts")
  3264. {
  3265. //print("Found a part with SpareParts!");
  3266. if (resource.amount < 0.25)
  3267. {
  3268. ScreenMessages.PostScreenMessage(new ScreenMessage("We ran out of SpareParts, can't finish this job!", 3f, ScreenMessageStyle.UPPER_CENTER));
  3269.  
  3270. fixOngoing = false;
  3271. jobName = "nil";
  3272. takeResOnce = false;
  3273. }
  3274. else if (resource.amount >= 0.25)
  3275. {
  3276. if (takeResOnce == true)
  3277. {
  3278. resource.amount = resource.amount - 0.25;
  3279. //print("Job completed in... " + fixTime + " seconds, at" + Time.time);
  3280. ScreenMessages.PostScreenMessage(new ScreenMessage("This Vessel is restored!", 10f, ScreenMessageStyle.UPPER_CENTER));
  3281. fixOngoing = false;
  3282. jobName = "nil";
  3283. takeResOnce = false;
  3284. foundParts = true;
  3285.  
  3286. foreach (Part pToFix in this.vessel.parts)
  3287. {
  3288. targetPart t = pToFix.GetComponent<targetPart>();
  3289. t.currentPartStructure = t.targetStructure;
  3290. t.setCSinCNew = true;
  3291. t.part.SetHighlightColor(Color.clear);
  3292. t.part.SetHighlight(true);
  3293. t.part.gameObject.SendMessage("ApplyDamage", 1f);
  3294. t.hasBeenHit = false;
  3295. t.isSinking = false;
  3296. t.targetIsBurning = false;
  3297. t.targetBurnedOut = false;
  3298. t.torpWaterlinePenetration = false;
  3299. t.wasHitByIncindiary = false;
  3300. enablePartFunctions();
  3301. }
  3302.  
  3303. }
  3304. }
  3305. }
  3306. }
  3307.  
  3308. }
  3309. if (foundParts != true)
  3310. {
  3311. ScreenMessages.PostScreenMessage(new ScreenMessage("I pulled this all apart for nothing. Without spare parts we can't fix this!", 3f, ScreenMessageStyle.UPPER_CENTER));
  3312.  
  3313. fixOngoing = false;
  3314. jobName = "nil";
  3315. takeResOnce = false;
  3316. }
  3317. }
  3318.  
  3319. }
  3320.  
  3321. if (HighLogic.LoadedSceneIsFlight && !this.vessel.isEVA)
  3322. {
  3323. thisWayUp = (this.vessel.transform.position - this.vessel.mainBody.position).normalized;
  3324.  
  3325.  
  3326. if (firstRun == true)
  3327. {
  3328. vesselMass = this.vessel.GetTotalMass();
  3329.  
  3330. checkMeshVolume();
  3331.  
  3332. targList = new List<targetPart>();
  3333. sinkList = new List<targetPart>();
  3334. countList = new List<targetPart>();
  3335.  
  3336. if (objectType == "targetObj" && hasBeenHit == false && weKnowOrigMass == false)
  3337. {
  3338. originalMass = (part.GetResourceMass() + part.mass);
  3339. currentMass = originalMass;
  3340.  
  3341. if (targetPartVolume == 0)
  3342. {
  3343. targetPartVolume = thisPartMeshVolume;
  3344. }
  3345. if (targetStructure == 0f)
  3346. {
  3347. targetStructure = ((targetPartVolume * targetHardness) * targetNotVoid) / 20f;
  3348. if (targetStructure < 1f && targetStructure > 0f) targetStructure = 1f;
  3349.  
  3350. }
  3351. currentPartStructure = targetStructure;
  3352.  
  3353. currentPartTemp = part.temperature;
  3354.  
  3355. try
  3356. {
  3357. foundDmgState = this.part.FindModelTransform("dmgState");
  3358. }
  3359. catch
  3360. {
  3361. print("Part has no Damage Model - no swap will happen");
  3362. }
  3363.  
  3364. if (foundDmgState != null)
  3365. {
  3366. Transform affectDmgState = this.part.FindModelTransform("dmgState");
  3367. affectDmgState.GetComponent<MeshRenderer>().enabled = false;
  3368. Transform affectCleanState = this.part.FindModelTransform("targetPart");
  3369. affectCleanState.GetComponent<MeshRenderer>().enabled = true;
  3370. }
  3371.  
  3372. }
  3373. else if (objectType == "targetObj" && weKnowOrigMass == true)
  3374. {
  3375.  
  3376. this.part.mass = currentMass;
  3377.  
  3378. }
  3379.  
  3380.  
  3381.  
  3382. firstRun = false;
  3383. }
  3384.  
  3385. if (this.part.vessel.loaded)
  3386. {
  3387.  
  3388. if (this.currentPartStructure == -123f && thisPartRestored == true)
  3389. {
  3390. disablePartFunctions();
  3391. this.part.SetHighlightColor(Color.yellow);
  3392. this.part.SetHighlight(true);
  3393. //print("Past the condition, check for yellow");
  3394.  
  3395. thisPartRestored = false;
  3396. }
  3397.  
  3398. if (setCSinCNew == true)
  3399. {
  3400. setColliderStateInChildren(this.gameObject, 0);
  3401. setCSinCNew = false;
  3402. }
  3403.  
  3404. thisTargetPOS = this.part.transform.position;
  3405. warheadModifier = 0;
  3406. if (vessel.GetTotalMass() != 0 && weKnowOrigMass == false)
  3407. {
  3408. vesselOriginalTotalMass = vessel.GetTotalMass();
  3409. weKnowOrigMass = true;
  3410.  
  3411. #region CountTargetFloatingHullParts
  3412. foreach (Part p in vessel.parts)
  3413. {
  3414. PartModule m = p.GetComponent<PartModule>();
  3415.  
  3416. if (m is targetPart)
  3417. {
  3418. targetPart countParts = m.GetComponent<targetPart>();
  3419. if (countParts != null && countParts.isSinking == false && countParts.targetType == 1) // Look for all floating hull parts.
  3420. {
  3421. //print("past the conditions");
  3422. countList.Add(countParts);
  3423.  
  3424. if (countList.Count > 0)
  3425. {
  3426. countedTargetParts = countList.Count; //just floating hull parts!!!
  3427. }
  3428. }
  3429. }
  3430. }
  3431. #endregion
  3432. checkCritSink = countedTargetParts * targetPartVolume;
  3433. }
  3434.  
  3435.  
  3436.  
  3437.  
  3438.  
  3439.  
  3440. if (currentPartStructure < targetStructure && part.WaterContact == true || torpWaterlinePenetration == true && part.WaterContact == true)
  3441. {
  3442. isSinking = true;
  3443.  
  3444. if(vessel.altitude < -10.0) targetIsBurning = false;
  3445.  
  3446. if (vessel.altitude < -300.0)
  3447. {
  3448. //print("Ship is sunk, get rid of it!");
  3449. foreach (Part p in vessel.Parts)
  3450. {
  3451. FXMonger.Explode(this.part, this.part.transform.position, 1f);
  3452. p.explode();
  3453.  
  3454. }
  3455.  
  3456.  
  3457. }
  3458.  
  3459. }
  3460. else
  3461. {
  3462. isSinking = false;
  3463.  
  3464. sinkStartTime = 0;
  3465. countSTimer = 0;
  3466.  
  3467. }
  3468.  
  3469.  
  3470.  
  3471. if (this.part.temperature > (this.part.maxTemp * 0.8f))
  3472. {
  3473. this.targetIsBurning = true;
  3474. }
  3475. if (targetBurnedOut == true)
  3476. {
  3477. float coolDown = FlightGlobals.getExternalTemperature((float)this.vessel.altitude, this.vessel.mainBody);
  3478. this.part.temperature = Mathf.Lerp(this.part.temperature, coolDown, 1f);
  3479. }
  3480.  
  3481. if (targetIsBurning == true && part.vessel.atmDensity > 0.3 && targetBurnedOut == false)
  3482. {
  3483.  
  3484. part.temperature += (heatProduction * (float)rndNumber.rndDouble(0.85, 1.25)) * TimeWarp.deltaTime;
  3485.  
  3486. currentPartTemp = part.temperature;
  3487. if (this.part.temperature > this.part.maxTemp * 0.1f && this.targetStructure > 1.5f)
  3488. {
  3489. if (fxFireInstance == null || fxFireInstance.activeInHierarchy == false)
  3490. {
  3491. setFireFX();
  3492.  
  3493. try
  3494. {
  3495.  
  3496. fxFireInstance = GameDatabase.Instance.GetModel(useFireFX);
  3497. }
  3498. catch
  3499. {
  3500. print("Problem locating fireFX");
  3501. }
  3502.  
  3503. if (fxFireInstance != null)
  3504. {
  3505. //print("ordinanceInstance is not null!");
  3506. fxFireInstance.SetActive(true);
  3507. fxFireInstance.transform.position = this.part.transform.position;
  3508. fxFireInstance.transform.parent = this.part.transform;
  3509. fxFireInstance.gameObject.layer = 0;
  3510.  
  3511. }
  3512.  
  3513. }
  3514.  
  3515. if (fireDieTimer > 0f)
  3516. {
  3517. fireDieTimer--;
  3518.  
  3519. if (fireDieTimer <= 0f)
  3520. {
  3521. float fireFighter = 0f;
  3522.  
  3523. fireTicker++;
  3524.  
  3525. float fireDiesChance = 5f;
  3526. if (wasHitByIncindiary == true) fireDiesChance *= 0.7f;
  3527. if (fuelLeak == true) fireDiesChance *= 0.15f;
  3528.  
  3529. if (kerbalFightsFire == true)
  3530. {
  3531. fireFighter = 5f;
  3532. }
  3533.  
  3534. fireDiesChance *= ((fireTicker * 0.025f) * fireFighter);
  3535.  
  3536.  
  3537. float randomNumber = (float)rndNumber.rndRoll(1, 100);
  3538.  
  3539.  
  3540. if (randomNumber < fireDiesChance)
  3541. {
  3542. targetIsBurning = false;
  3543. fireTicker = 0f;
  3544. float coolDown = FlightGlobals.getExternalTemperature((float)this.vessel.altitude, this.vessel.mainBody);
  3545. this.part.temperature = Mathf.Lerp(this.part.temperature, coolDown, 1f);
  3546. hasBeenHit = false;
  3547. fxFireInstance.SetActive(false);
  3548. }
  3549.  
  3550. fireDieTimer = 110f;
  3551.  
  3552. }
  3553. }
  3554.  
  3555.  
  3556. if (this.part.temperature > this.part.maxTemp * 0.6f)
  3557. {
  3558.  
  3559. PartResourceList resourceList = this.part.Resources;
  3560. foreach (PartResource resource in resourceList)
  3561. {
  3562. if (resource.resourceName == "LiquidFuel" || resource.resourceName == "HEcharge" || resource.resourceName == "SolidFuel")
  3563. {
  3564. float chanceToBlow = this.part.temperature * 0.0005f;
  3565. float rollTheDice = (float)rndNumber.rndRoll(1, 200);
  3566. if (rollTheDice < chanceToBlow)
  3567. {
  3568. FXMonger.Explode(this.part, this.part.transform.position, ((float)resource.amount * 0.125f));
  3569. this.targetBurnedOut = true;
  3570. print("Fuel Explosion, fire is out!");
  3571. fxFireInstance = null;
  3572.  
  3573. targetIsBurning = false;
  3574. currentPartStructure = -1f;
  3575. doTheDamage();
  3576. targList.Clear();
  3577.  
  3578. if (rollTheDice < (chanceToBlow * 0.5f))
  3579. {
  3580. this.part.explode();
  3581. }
  3582. }
  3583. }
  3584.  
  3585. }
  3586. }
  3587.  
  3588.  
  3589. if (this.part.temperature > this.part.maxTemp * 0.9f)
  3590. {
  3591. targetBurnedOut = true;
  3592. print("Part Burned Out!");
  3593. fxFireInstance = null;
  3594.  
  3595. targetIsBurning = false;
  3596. currentPartStructure = -1f;
  3597. bombJustExploded = true;
  3598. doTheDamage();
  3599. targList.Clear();
  3600.  
  3601. }
  3602.  
  3603. }
  3604.  
  3605. }
  3606.  
  3607. if (targetIsBurning == false && targetBurnedOut == false || part.vessel.atmDensity > 0.3)
  3608. {
  3609.  
  3610. targetIsBurning = false;
  3611. currentPartTemp = part.temperature;
  3612. targList.Clear();
  3613.  
  3614. }
  3615.  
  3616. if (fuelLeak == true)
  3617. {
  3618. checkFuelLoss();
  3619. }
  3620.  
  3621. #region FIRE START CODE ^^^^^^^^^^^^~^~^~^~^~^~^~^~^~^~^~^^^^^^^^^^^^^^
  3622.  
  3623. if (currentPartStructure < targetStructure && hasBeenHit == true || fuelLeak == true)
  3624. {
  3625. if (part.vessel.atmDensity > 0.3 && targetIsBurning == false && isSinking == false && targetBurnedOut == false)
  3626. {
  3627. if (fireStartTimer > 0f)
  3628. {
  3629. fireStartTimer--;
  3630.  
  3631. if (fireStartTimer <= 0f)
  3632. {
  3633. float chanceOfFire = rndNumber.rndFloat(0.35f, 1.1f);
  3634. if (warheadModifier == 1f) chanceOfFire *= 1.2f;
  3635. if (wasHitByIncindiary == true) chanceOfFire *= 1.4f;
  3636. if (fuelLeak == true) chanceOfFire *= 1.4f;
  3637. //print(chanceOfFire + " %");
  3638.  
  3639. float randomNumber = rndNumber.rndFloat(1f, 100f);
  3640. if (randomNumber < chanceOfFire)
  3641. {
  3642. targetIsBurning = true;
  3643.  
  3644. }
  3645.  
  3646. fireStartTimer = 30f;
  3647. }
  3648. }
  3649.  
  3650. }
  3651. }
  3652. #endregion
  3653.  
  3654. }
  3655. }
  3656. }
  3657.  
  3658. private void checkPenetrate()
  3659. {
  3660.  
  3661. if (warheadModifier == 3f) projHardness = (projHardness * 1.75f);
  3662. if (warheadModifier == 2f) projHardness = (projHardness * 0.75f);
  3663. float adjustVelocityChance = projectileVelocity;
  3664. if (adjustVelocityChance < 0f) adjustVelocityChance = 1f;
  3665. if (projHardness > this.targetHardness)
  3666. {
  3667. projPenBaseline = 50f;
  3668. }
  3669. else projPenBaseline = 0f;
  3670. penetrateChance = ((((projHardness / this.targetHardness) * projPenetrate) + projPenBaseline) * (adjustVelocityChance / 300f) / (this.currentPartStructure/5f)) + (projectileMass * 95f);
  3671.  
  3672.  
  3673. if (penetrateChance <= 1f) penetrateChance = 1f;
  3674. if (penetrateChance > 99f) penetrateChance = 99f;
  3675.  
  3676. float penRoll = rndNumber.rndRoll(0, 100);
  3677. if (penRoll < penetrateChance)
  3678. {
  3679. //print("PENETRATION! : penchance was " + penetrateChance + "Penetrate roll was " + penRoll);
  3680. bombJustExploded = true;
  3681. doTheDamage();
  3682. fLeakRate = (double)projPenetrate * 0.033;
  3683. }
  3684. else
  3685. {
  3686. //print("NO PENETRATION : penchance was " + penetrateChance + "Penetrate roll was " + penRoll);
  3687. }
  3688.  
  3689. if (!bulletHitM1.audio.isPlaying)
  3690. {
  3691. bulletHitM1.audio.Play();
  3692. }
  3693. else
  3694. {
  3695. bulletHitM2.audio.Play();
  3696. }
  3697.  
  3698. this.rigidbody.AddForceAtPosition(Vector3.forward * ((projectileVelocity * projectileMass * projHardness) / (vesselMass * 150f)), this.transform.position, ForceMode.Impulse);
  3699.  
  3700. }
  3701.  
  3702.  
  3703. private void doTheDamage()
  3704. {
  3705. bool avoidDamage = false;
  3706.  
  3707. relayIFF isIFF = base.part.GetComponent<relayIFF>();
  3708. if (isIFF == null)
  3709. {
  3710. isIFF = base.part.GetComponentsInChildren<relayIFF>().FirstOrDefault();
  3711. }
  3712. if (isIFF != null)
  3713. {
  3714. avoidDamage = true;
  3715. }
  3716.  
  3717. if (bombJustExploded == true && avoidDamage == false)
  3718. {
  3719. float isHEModifier = 1f;
  3720. if (warheadModifier == 1f) isHEModifier = 2.5f;
  3721. if (warheadModifier == 2f) wasHitByIncindiary = true;
  3722. if (hitIsTorpedo == true)
  3723. {
  3724. isHEModifier = 10f;
  3725. torpWaterlinePenetration = true;
  3726. }
  3727.  
  3728. float randomDamageMod = ((float)rndNumber.rndDouble(0.01, 1.0) + 0.75f);
  3729. isHEModifier = isHEModifier * randomDamageMod;
  3730.  
  3731. structHitLoss = ((projectileMass * projectileVelocity) * (projHardness / targetHardness)) * isHEModifier;
  3732.  
  3733. currentPartStructure = currentPartStructure - structHitLoss;
  3734. print("Impact Vel: " + projectileVelocity + "after suffering " + structHitLoss + " damage, Structure is now " + currentPartStructure);
  3735.  
  3736. float perDamaged = (currentPartStructure / targetStructure);
  3737. if (perDamaged < 0.01f) perDamaged = 0.01f;
  3738.  
  3739. this.part.gameObject.SendMessage("ApplyDamage", perDamaged);
  3740.  
  3741. if (currentPartStructure < 0f)
  3742. {
  3743.  
  3744. float determineFate = rndNumber.rndRoll(1, 100);
  3745. float fateCheckValue = 5f;
  3746. if ((targetStructure * 0.25f) < (projPenetrate * 0.5f)) fateCheckValue = 7.5f;
  3747. if ((targetStructure * 0.5f) < (projPenetrate * 0.5f)) fateCheckValue = 12.5f;
  3748. if ((targetStructure * 0.75f) < (projPenetrate * 0.5f)) fateCheckValue = 25f;
  3749. if (targetStructure < (projPenetrate * 0.5f)) fateCheckValue = 50f;
  3750.  
  3751. if ((float)determineFate <= fateCheckValue)
  3752. {
  3753. //print("This target part is totally destroyed!");
  3754. if (this.part.mass > 3.5f)
  3755. {
  3756. doIDExplode();
  3757. }
  3758. this.part.explode();
  3759. }
  3760. else if ((float)determineFate > fateCheckValue)
  3761. {
  3762. //print("This target part is destroyed! repair it later!");
  3763. currentPartStructure = 0f;
  3764. this.part.SetHighlightColor(Color.yellow);
  3765. this.part.SetHighlight(true);
  3766. this.part.gameObject.SendMessage("ApplyDamage", 0.01f);
  3767.  
  3768. setColliderStateInChildren(this.gameObject, 1);
  3769.  
  3770. if (foundDmgState != null)
  3771. {
  3772. //print("Changing to the damage model");
  3773. Transform affectDmgState = this.part.FindModelTransform("dmgState");
  3774. affectDmgState.GetComponent<MeshRenderer>().enabled = true;
  3775. Transform affectCleanState = this.part.FindModelTransform("targetPart");
  3776. affectCleanState.GetComponent<MeshRenderer>().enabled = false;
  3777. }
  3778. disablePartFunctions();
  3779.  
  3780.  
  3781. }
  3782.  
  3783. if (isSinking == true)
  3784. {
  3785. targetIsBurning = false;
  3786. }
  3787.  
  3788. }
  3789.  
  3790.  
  3791. hasBeenHit = true;
  3792. bombJustExploded = false;
  3793.  
  3794. }
  3795.  
  3796. }
  3797.  
  3798. public static void setColliderStateInChildren(GameObject rootObject, int layerInt)
  3799. {
  3800. Collider[] colliders = rootObject.GetComponentsInChildren<Collider>(true);
  3801. for (int i = 0; i < colliders.Length; i++)
  3802. {
  3803.  
  3804. colliders[i].gameObject.layer = layerInt;
  3805.  
  3806. }
  3807. }
  3808.  
  3809. public void disablePartFunctions()
  3810. {
  3811. if(this.currentPartStructure <= 0f)
  3812. {
  3813.  
  3814. if (this.gameObject.GetComponentInChildren<ModuleEngines>() == true)
  3815. {
  3816. ModuleEngines thisTargetEngine = this.gameObject.GetComponentInChildren<ModuleEngines>();
  3817. thisTargetEngine.allowRestart = false;
  3818. thisTargetEngine.Shutdown();
  3819. thisTargetEngine.DeactivateRunningFX();
  3820. thisTargetEngine.DeactivatePowerFX();
  3821. thisTargetEngine.enabled = false;
  3822.  
  3823. }
  3824. if (this.gameObject.GetComponentInChildren<ModuleEnginesFX>() == true)
  3825. {
  3826. ModuleEnginesFX thisTargetEngine = this.gameObject.GetComponentInChildren<ModuleEnginesFX>();
  3827. thisTargetEngine.allowRestart = false;
  3828. thisTargetEngine.Shutdown();
  3829. thisTargetEngine.DeactivateLoopingFX();
  3830. thisTargetEngine.isEnabled = false;
  3831.  
  3832. }
  3833. if (this.gameObject.GetComponentInChildren<IDDepot>() == true)
  3834. {
  3835. float chanceToBlow = (float)rndNumber.rndDouble(0.01, 75.0) * projPenetrate;
  3836. float makeBlowRoll = rndNumber.rndRoll(0, 100);
  3837. if (chanceToBlow > makeBlowRoll)
  3838. {
  3839. doIDExplode();
  3840. FXMonger.Explode(this.part, this.part.transform.position, this.currentMass);
  3841. this.part.explode();
  3842.  
  3843. }
  3844. }
  3845. if (this.gameObject.GetComponentInChildren<ControlSurface>() == true)
  3846. {
  3847.  
  3848. ControlSurface thisTargetSurface = this.gameObject.GetComponentInChildren<ControlSurface>();
  3849. wingOriginalSurfaceArea = thisTargetSurface.deflectionLiftCoeff;
  3850. thisTargetSurface.ctrlSurfaceRange = rndNumber.rndRoll(0, 20);
  3851. thisTargetSurface.deflectionLiftCoeff = wingOriginalSurfaceArea * (float)rndNumber.rndDouble(0.01, 0.95);
  3852. print("Wing has taken damage");
  3853.  
  3854. }
  3855. if (this.gameObject.GetComponentInChildren<FuelLine>() == true)
  3856. {
  3857.  
  3858. FuelLine thisTargetFuelLine = this.gameObject.GetComponentInChildren<FuelLine>();
  3859. thisTargetFuelLine.fuelCrossFeed = false;
  3860.  
  3861. print("Fuel line has taken damage!");
  3862.  
  3863. }
  3864.  
  3865. if (this.gameObject.GetComponentInChildren<ModuleReactionWheel>() == true)
  3866. {
  3867.  
  3868. ModuleReactionWheel thisTargetRWheel = this.gameObject.GetComponentInChildren<ModuleReactionWheel>();
  3869. thisTargetRWheel.PitchTorque = rndNumber.rndFloat(0f, 10f);
  3870. thisTargetRWheel.RollTorque = rndNumber.rndFloat(0f, 10f);
  3871. thisTargetRWheel.YawTorque = rndNumber.rndFloat(0f, 10f);
  3872.  
  3873. float chanceToBreak = (float)rndNumber.rndDouble(0.01, 50.0) * projPenetrate; // base chance to die
  3874. float makeBreakRoll = rndNumber.rndRoll(0,100);
  3875. if (chanceToBreak > makeBreakRoll)
  3876. {
  3877. thisTargetRWheel.wheelState = ModuleReactionWheel.WheelState.Broken;
  3878. }
  3879. print("Reaction Wheel is not working properly!");
  3880.  
  3881. }
  3882. if (this.gameObject.GetComponentInChildren<Light>() == true)
  3883. {
  3884.  
  3885. Light thisTargetLight = this.gameObject.GetComponentInChildren<Light>();
  3886.  
  3887. thisTargetLight.enabled = false;
  3888. if (this.gameObject.GetComponentInChildren<ModuleLight>() == true)
  3889. {
  3890. ModuleLight thisTargetLightModule = this.gameObject.GetComponentInChildren<ModuleLight>();
  3891. thisTargetLightModule.isOn = false;
  3892. thisTargetLightModule.LightsOff();
  3893.  
  3894. }
  3895.  
  3896. print("Light was damaged");
  3897.  
  3898. }
  3899. if (this.gameObject.GetComponentInChildren<projectileWS>() == true)
  3900. {
  3901. projectileWS thisTargetGun = this.gameObject.GetComponentInChildren<projectileWS>();
  3902. thisTargetGun.ctrlTurret = false;
  3903. thisTargetGun.fireOverride = true;
  3904. print("This ID gun is out of action!!!");
  3905.  
  3906. }
  3907.  
  3908. if (this.gameObject.GetComponentInChildren<CommandPod>() == true)
  3909. {
  3910. CommandPod thisTargetCommand = this.gameObject.GetComponentInChildren<CommandPod>();
  3911. thisTargetCommand.Kd = rndNumber.rndRoll(0, 1);
  3912. thisTargetCommand.Kp = rndNumber.rndRoll(0, 1);
  3913. thisTargetCommand.linPower = rndNumber.rndRoll(0, 1);
  3914. thisTargetCommand.rotPower = rndNumber.rndRoll(0, 1);
  3915. float chanceToDie = (float)rndNumber.rndDouble(0.01, 20.0) * projPenetrate; // base chance to die
  3916. float makeDieRoll = rndNumber.rndRoll(0,100);
  3917. if (chanceToDie > makeDieRoll)
  3918. {
  3919. ProtoCrewMember getPilot = this.vessel.GetVesselCrew().FirstOrDefault();
  3920. getPilot.Die();
  3921. }
  3922.  
  3923. }
  3924. if (this.gameObject.GetComponentInChildren<LandingGear>() == true)
  3925. {
  3926. LandingGear thisTargetGear = this.gameObject.GetComponentInChildren<LandingGear>();
  3927. thisTargetGear.frozen = true;
  3928. }
  3929. if (this.gameObject.GetComponentInChildren<ModuleWheel>() == true)
  3930. {
  3931. ModuleWheel thisTargetWheel = this.gameObject.GetComponentInChildren<ModuleWheel>();
  3932. thisTargetWheel.isDamaged = true;
  3933.  
  3934. }
  3935.  
  3936. PartResourceList resourceList = this.part.Resources;
  3937. foreach (PartResource resource in resourceList)
  3938. {
  3939. if (resource.resourceName == "LiquidFuel")
  3940. {
  3941. fuelLeak = true;
  3942. leakToLevel = resource.maxAmount * rndNumber.rndDouble(0.01, 1.0);
  3943. }
  3944.  
  3945. if (resource.resourceName == "ElectricCharge")
  3946. {
  3947. resource.flowMode = PartResource.FlowMode.None;
  3948. resource.flowState = false;
  3949. resource.amount = 0.0;
  3950. }
  3951.  
  3952. if (resource.resourceName.Contains("Ammo"))
  3953. {
  3954. float chanceToBlow = (float)rndNumber.rndDouble(0.01, 75.0) * projPenetrate;
  3955. float makeBlowRoll = rndNumber.rndRoll(0,100);
  3956. if (chanceToBlow > makeBlowRoll)
  3957. {
  3958. FXMonger.Explode(this.part, this.part.transform.position, (float)resource.amount);
  3959. this.part.explode();
  3960.  
  3961. }
  3962. }
  3963.  
  3964.  
  3965. }
  3966. if (this.currentPartStructure < 0f)
  3967. {
  3968. this.currentPartStructure = 0f;
  3969. }
  3970. }
  3971. }
  3972.  
  3973. public void enablePartFunctions()
  3974. {
  3975.  
  3976.  
  3977. if (this.gameObject.GetComponentInChildren<ModuleEngines>() == true)
  3978. {
  3979. ModuleEngines thisTargetEngine = this.gameObject.GetComponentInChildren<ModuleEngines>();
  3980. thisTargetEngine.allowRestart = true;
  3981. thisTargetEngine.enabled = true;
  3982.  
  3983. }
  3984. if (this.gameObject.GetComponentInChildren<ModuleEnginesFX>() == true)
  3985. {
  3986. ModuleEnginesFX thisTargetEngine = this.gameObject.GetComponentInChildren<ModuleEnginesFX>();
  3987. thisTargetEngine.allowRestart = true;
  3988. thisTargetEngine.isEnabled = true;
  3989.  
  3990. }
  3991.  
  3992. if (this.gameObject.GetComponentInChildren<ControlSurface>() == true)
  3993. {
  3994.  
  3995. ControlSurface thisTargetSurface = this.gameObject.GetComponentInChildren<ControlSurface>();
  3996.  
  3997. thisTargetSurface.ctrlSurfaceRange = 20f;
  3998. thisTargetSurface.deflectionLiftCoeff = wingOriginalSurfaceArea;
  3999. print("control surface is fixed");
  4000.  
  4001. }
  4002. if (this.gameObject.GetComponentInChildren<FuelLine>() == true)
  4003. {
  4004.  
  4005. FuelLine thisTargetFuelLine = this.gameObject.GetComponentInChildren<FuelLine>();
  4006. thisTargetFuelLine.fuelCrossFeed = true;
  4007.  
  4008. print("Fuel line repaired!");
  4009.  
  4010. }
  4011.  
  4012. if (this.gameObject.GetComponentInChildren<ModuleReactionWheel>() == true)
  4013. {
  4014.  
  4015. ModuleReactionWheel thisTargetRWheel = this.gameObject.GetComponentInChildren<ModuleReactionWheel>();
  4016. thisTargetRWheel.PitchTorque = 10f;
  4017. thisTargetRWheel.RollTorque = 10f;
  4018. thisTargetRWheel.YawTorque = 10f;
  4019.  
  4020. thisTargetRWheel.wheelState = ModuleReactionWheel.WheelState.Active;
  4021.  
  4022. print("Reaction Wheel is fixed!");
  4023.  
  4024. }
  4025. if (this.gameObject.GetComponentInChildren<Light>() == true)
  4026. {
  4027.  
  4028. Light thisTargetLight = this.gameObject.GetComponentInChildren<Light>();
  4029. thisTargetLight.enabled = true;
  4030. if (this.gameObject.GetComponentInChildren<ModuleLight>() == true)
  4031. {
  4032. ModuleLight thisTargetLightModule = this.gameObject.GetComponentInChildren<ModuleLight>();
  4033. thisTargetLightModule.isOn = true;
  4034. thisTargetLightModule.LightsOn();
  4035.  
  4036. }
  4037.  
  4038. print("Light is fixed");
  4039.  
  4040. }
  4041. if (this.gameObject.GetComponentInChildren<projectileWS>() == true)
  4042. {
  4043. projectileWS thisTargetGun = this.gameObject.GetComponentInChildren<projectileWS>();
  4044. thisTargetGun.fireOverride = false;
  4045. print("This ID gun is repaired!!!");
  4046.  
  4047. }
  4048.  
  4049. if (this.gameObject.GetComponentInChildren<CommandPod>() == true)
  4050. {
  4051. CommandPod thisTargetCommand = this.gameObject.GetComponentInChildren<CommandPod>();
  4052. thisTargetCommand.Kd = 1f;
  4053. thisTargetCommand.Kp = 1f;
  4054. thisTargetCommand.linPower = 1f;
  4055. thisTargetCommand.rotPower = 1f;
  4056.  
  4057. }
  4058. if (this.gameObject.GetComponentInChildren<LandingGear>() == true)
  4059. {
  4060. LandingGear thisTargetGear = this.gameObject.GetComponentInChildren<LandingGear>();
  4061. thisTargetGear.frozen = false;
  4062. }
  4063. if (this.gameObject.GetComponentInChildren<ModuleWheel>() == true)
  4064. {
  4065. ModuleWheel thisTargetWheel = this.gameObject.GetComponentInChildren<ModuleWheel>();
  4066. thisTargetWheel.isDamaged = false;
  4067.  
  4068. }
  4069.  
  4070. PartResourceList resourceList = this.part.Resources;
  4071. foreach (PartResource resource in resourceList)
  4072. {
  4073. if (resource.resourceName == "LiquidFuel")
  4074. {
  4075. fuelLeak = false;
  4076. leakToLevel = resource.maxAmount;
  4077. }
  4078.  
  4079. if (resource.resourceName == "ElectricCharge")
  4080. {
  4081. resource.flowMode = PartResource.FlowMode.Both;
  4082. resource.flowState = true;
  4083. resource.amount = resource.maxAmount * 0.2f;
  4084. }
  4085.  
  4086.  
  4087.  
  4088.  
  4089. }
  4090.  
  4091.  
  4092. }
  4093.  
  4094.  
  4095. public void checkSinkSpread(targetPart sinkSel)
  4096. {
  4097. float chanceOfSink = (targetStructure / currentPartStructure) * 10;
  4098.  
  4099. if (chanceOfSink <= 5) chanceOfSink = 5;
  4100. int randomNumber = UnityEngine.Random.Range(0, 100);
  4101. sinkCheckTime = (sinkCheckTime += 20);
  4102. if (randomNumber < chanceOfSink)
  4103. {
  4104. setConditionS = true;
  4105. }
  4106. }
  4107.  
  4108. public void checkMeshVolume()
  4109. {
  4110. float runningTotal = 0f;
  4111. float totalAvg = 0f;
  4112. MeshFilter[] getAllMeshes = base.part.GetComponentsInChildren<MeshFilter>();
  4113. if (getAllMeshes != null || getAllMeshes.Length <= 0)
  4114. {
  4115. foreach (MeshFilter mF in getAllMeshes)
  4116. {
  4117. if (mF != null)
  4118. {
  4119. runningTotal += VolumeOfMesh(mF.sharedMesh);
  4120. totalAvg = runningTotal / (float)getAllMeshes.Count();
  4121. }
  4122. }
  4123. }
  4124.  
  4125. thisPartMeshVolume = totalAvg;
  4126.  
  4127. if (thisPartMeshVolume < 1f)
  4128. {
  4129. float isThisValueHigher = 0f;
  4130.  
  4131. if (this.part.collider != null)
  4132. {
  4133. isThisValueHigher = (this.part.collider.bounds.size.y * this.part.collider.bounds.size.x * this.part.collider.bounds.size.z); //alternate sizing method
  4134. }
  4135.  
  4136. if (isThisValueHigher > thisPartMeshVolume) thisPartMeshVolume = isThisValueHigher;
  4137. }
  4138.  
  4139.  
  4140. //Known problem part list: Some stock parts have crazy values...
  4141. if (this.part.partName.Contains("airScoop") || this.part.name == "airScoop" || base.part.partName == "airScoop")
  4142. {
  4143. thisPartMeshVolume = 0.15f;
  4144. }
  4145.  
  4146. if (this.part.partName.Contains("wingConnector") || this.part.name == "wingConnector" || base.part.partName == "wingConnector")
  4147. {
  4148. thisPartMeshVolume = 0.75f;
  4149. }
  4150. if (this.part.partName.Contains("structuralWing") || this.part.name == "structuralWing" || base.part.partName == "structuralWing")
  4151. {
  4152. thisPartMeshVolume = 0.85f;
  4153. }
  4154. if (this.part.partName.Contains("smallCtrlSrf") || this.part.name == "smallCtrlSrf" || base.part.partName == "smallCtrlSrf")
  4155. {
  4156. thisPartMeshVolume = 0.2f;
  4157. }
  4158. if (this.part.partName.Contains("StandardCtrlSrf") || this.part.name == "StandardCtrlSrf" || base.part.partName == "StandardCtrlSrf")
  4159. {
  4160. thisPartMeshVolume = 0.4f;
  4161. }
  4162. if (this.part.partName.Contains("CanardController") || this.part.name == "CanardController" || base.part.partName == "CanardController")
  4163. {
  4164. thisPartMeshVolume = 0.42f;
  4165. }
  4166. if (this.part.partName.Contains("deltaWing") || this.part.name == "deltaWing" || base.part.partName == "deltaWing")
  4167. {
  4168. thisPartMeshVolume = 1f;
  4169. }
  4170. if (this.part.partName.Contains("sweptWing") || this.part.name == "sweptWing" || base.part.partName == "sweptWing")
  4171. {
  4172. thisPartMeshVolume = 0.85f;
  4173. }
  4174. if (this.part.partName.Contains("tailfin") || this.part.name == "tailfin" || base.part.partName == "tailfin")
  4175. {
  4176. thisPartMeshVolume = 0.44f;
  4177. //print(this.part.partName + " has been fixed");
  4178. }
  4179. if (this.part.partName.Contains("R8winglet") || this.part.name == "R8winglet" || base.part.partName == "R8winglet")
  4180. {
  4181. thisPartMeshVolume = 0.35f;
  4182. }
  4183. if (this.part.partName.Contains("winglet3") || this.part.name == "winglet3" || base.part.partName == "winglet3")
  4184. {
  4185. thisPartMeshVolume = 0.325f;
  4186. }
  4187. if (this.part.partName.Equals("winglet") || this.part.name == "winglet" || base.part.partName == "winglet")
  4188. {
  4189. thisPartMeshVolume = 0.315f;
  4190. }
  4191. if (this.part.partName.Contains("CircularIntake") || this.part.name == "CircularIntake" || base.part.partName == "CircularIntake")
  4192. {
  4193. thisPartMeshVolume = 0.15f;
  4194. }
  4195. if (this.part.partName.Contains("ramAirIntake") || this.part.name == "ramAirIntake" || base.part.partName == "ramAirIntake")
  4196. {
  4197. thisPartMeshVolume = 0.25f;
  4198. }
  4199. if (this.part.partName.Contains("structuralPanel") || this.part.name == "structuralPanel" || base.part.partName == "structuralPanel")
  4200. {
  4201. targetHardness = 250f;
  4202. }
  4203. if (this.part.partName.Contains("roverBody") || this.part.name == "roverBody" || base.part.partName == "roverBody")
  4204. {
  4205. thisPartMeshVolume = 3.25f;
  4206. targetHardness = 200f;
  4207. }
  4208. if (this.part.name.Contains("FSbomb") || this.part.name == "FStailWingLarge" || base.part.partName == "FSbomberFuselage")
  4209. {
  4210. targetHardness = 170f;
  4211. targetNotVoid = 0.075f;
  4212. }
  4213. if (this.part.name.Contains("RepairStation") || this.part.name == "RepairStation" || base.part.partName == "RepairStation")
  4214. {
  4215. //print("Fixing Repair Station");
  4216. targetHardness = 220f;
  4217. targetNotVoid = 0.00000015f;
  4218. }
  4219. if (this.part.partName.Contains("roverWheel") || this.part.name == "roverWheel" || base.part.partName == "roverWheel" || this.part.partName.Contains("wheelMed"))
  4220. {
  4221. targetHardness = 250f;
  4222. }
  4223.  
  4224.  
  4225. }
  4226.  
  4227. public void setFireFX()
  4228. {
  4229. if (this.part.mass >= 3.5f)
  4230. {
  4231. this.useFireFX = "IDSkillfulR1/Effects/largeFire/model";
  4232. }
  4233. }
  4234.  
  4235.  
  4236.  
  4237. public void doIDExplode()
  4238. {
  4239. GameObject fxIDExplode = new GameObject();
  4240.  
  4241. if (fxIDExplode == null || fxIDExplode.activeInHierarchy == false)
  4242. {
  4243. try
  4244. {
  4245.  
  4246. fxIDExplode = GameDatabase.Instance.GetModel("IDSkillfulR1/Effects/IDexplode/model");
  4247. }
  4248. catch
  4249. {
  4250. print("Problem locating IDexplode");
  4251. }
  4252.  
  4253. if (fxIDExplode != null)
  4254. {
  4255.  
  4256. fxIDExplode.SetActive(true);
  4257. fxIDExplode.transform.position = this.part.transform.position;
  4258. fxIDExplode.transform.parent = this.part.transform;
  4259.  
  4260. fxIDExplode.AddComponent<endFx>();
  4261. Destroy(fxIDExplode, 4f * this.part.mass);
  4262.  
  4263. }
  4264.  
  4265. }
  4266. }
  4267.  
  4268. public void checkFuelLoss()
  4269. {
  4270. PartResourceList resourceList = this.part.Resources;
  4271. foreach (PartResource resource in resourceList)
  4272. {
  4273. if (resource.resourceName == "LiquidFuel")
  4274. {
  4275.  
  4276. resource.flowMode = PartResource.FlowMode.Out;
  4277. if (resource.amount > leakToLevel)
  4278. {
  4279. resource.amount -= fLeakRate * TimeWarp.deltaTime;
  4280. }
  4281.  
  4282.  
  4283. }
  4284. }
  4285. }
  4286.  
  4287. public void OnTriggerEnter(Collider theProjectile)
  4288. {
  4289. if (theProjectile.gameObject.GetComponent<impact>())
  4290. {
  4291. //print("Hitting Target Via Impact it has: " + currentPartStructure + " Structure");
  4292. if (theProjectile.rigidbody.velocity.magnitude > 50f && currentPartStructure > 0f)
  4293. {
  4294. #region hit effects for parts *******************************************FX
  4295. GameObject explosion = Part.Instantiate(UnityEngine.Resources.Load("Effects/fx_exhaustSparks_yellow")) as GameObject;
  4296. explosion.transform.localEulerAngles = Vector3.zero;
  4297. explosion.transform.localPosition = new Vector3(0, 0, 0);
  4298. explosion.transform.position = this.transform.position;
  4299. ParticleEmitter emitter = explosion.particleEmitter;
  4300. emitter.emit = false;
  4301. emitter.minSize = theProjectile.rigidbody.mass * 20f + 0.35f;
  4302. emitter.maxSize = theProjectile.rigidbody.mass * 50f + 0.75f;
  4303. emitter.minEnergy = (theProjectile.rigidbody.mass * theProjectile.rigidbody.velocity.magnitude) * 0.003f;
  4304. emitter.maxEnergy = (theProjectile.rigidbody.mass * theProjectile.rigidbody.velocity.magnitude) * 0.015f;
  4305. emitter.rndVelocity = Vector3.one * ((float)rndNumber.rndDouble(0.01, 1.2) * 0.75f);
  4306. emitter.localVelocity = Vector3.zero;
  4307. emitter.useWorldSpace = true;
  4308. ParticleAnimator emitterAnimator = emitter.GetComponent<ParticleAnimator>();
  4309. emitterAnimator.sizeGrow = 0.03F;
  4310. Color[] emitterColors = emitterAnimator.colorAnimation;
  4311. emitterColors[0] = new Color(1f, 0f, 0f, 0.95f);
  4312. emitterColors[1] = new Color(1f, 1f, 1f, 0.95f);
  4313. emitterColors[2] = new Color(0.75f, 0.75f, 0.75f, 0.6f);
  4314. emitterColors[3] = new Color(0.5f, 0.5f, 0.5f, 0.4f);
  4315. emitterColors[4] = new Color(0f, 0f, 0f, 0.15f);
  4316. emitterAnimator.colorAnimation = emitterColors;
  4317.  
  4318. emitter.Emit(8);
  4319.  
  4320. #endregion
  4321.  
  4322. impact thisImpact = theProjectile.gameObject.GetComponent<impact>();
  4323. this.vessel.GoOffRails();
  4324. thisImpact.renderer.enabled = false;
  4325. projectileMass = thisImpact.rb.mass;
  4326. projectileVelocity = theProjectile.rigidbody.velocity.magnitude;
  4327. projPenetrate = thisImpact.useProjPenetrate;
  4328. projHardness = thisImpact.useHardness;
  4329. warheadModifier = thisImpact.useWarheadType;
  4330. checkPenetrate();
  4331.  
  4332. Destroy(thisImpact.gameObject);
  4333.  
  4334. }
  4335.  
  4336. }
  4337. else if (theProjectile.gameObject.GetComponent<fragImpact>() || theProjectile.gameObject.GetComponentInChildren<fragImpact>() || theProjectile.gameObject.GetComponentInParent<fragImpact>())
  4338. {
  4339. //print("Fragment hit Target Via FragImpact - it has: " + currentPartStructure + " Structure");
  4340.  
  4341. fragImpact thisFImpact = theProjectile.gameObject.GetComponent<fragImpact>();
  4342. if (thisFImpact != null)
  4343. {
  4344. fragImpactHandler = thisFImpact;
  4345. thisBRB = thisFImpact.gameObject.GetComponent<Rigidbody>();
  4346. if (thisBRB == null)
  4347. {
  4348. thisBRB = thisFImpact.gameObject.GetComponentInChildren<Rigidbody>();
  4349. if (thisBRB == null)
  4350. {
  4351. thisBRB = thisFImpact.gameObject.GetComponentInParent<Rigidbody>();
  4352. }
  4353. }
  4354. }
  4355.  
  4356. fragImpact thisF2Impact = theProjectile.gameObject.GetComponentInChildren<fragImpact>();
  4357. if (thisF2Impact != null)
  4358. {
  4359. fragImpactHandler = thisF2Impact;
  4360. thisBRB = thisF2Impact.gameObject.GetComponent<Rigidbody>();
  4361. if (thisBRB == null)
  4362. {
  4363. thisBRB = thisF2Impact.gameObject.GetComponentInChildren<Rigidbody>();
  4364. if (thisBRB == null)
  4365. {
  4366. thisBRB = thisF2Impact.gameObject.GetComponentInParent<Rigidbody>();
  4367. }
  4368. }
  4369. }
  4370.  
  4371. fragImpact thisF3Impact = theProjectile.gameObject.GetComponentInParent<fragImpact>();
  4372. if (thisF3Impact != null)
  4373. {
  4374. fragImpactHandler = thisF3Impact;
  4375. thisBRB = thisF3Impact.gameObject.GetComponent<Rigidbody>();
  4376. if (thisBRB == null)
  4377. {
  4378. thisBRB = thisF3Impact.gameObject.GetComponentInChildren<Rigidbody>();
  4379. if (thisBRB == null)
  4380. {
  4381. thisBRB = thisF3Impact.gameObject.GetComponentInParent<Rigidbody>();
  4382. }
  4383. }
  4384. }
  4385.  
  4386. if (thisBRB.velocity.magnitude > 5f && currentPartStructure > 0f)
  4387. {
  4388. if (this.vessel != FlightGlobals.ActiveVessel) this.vessel.GoOffRails();
  4389. projectileMass = fragImpactHandler.rigidbody.mass;
  4390. projectileVelocity = fragImpactHandler.rigidbody.velocity.magnitude;
  4391. projPenetrate = 400f;
  4392. projHardness = fragImpactHandler.fragHardness;
  4393. warheadModifier = fragImpactHandler.fragWarheadType;
  4394.  
  4395. checkPenetrate();
  4396.  
  4397. Destroy(fragImpactHandler.gameObject);
  4398. }
  4399.  
  4400. }
  4401. else if (theProjectile.gameObject.GetComponent<IDDropBomb>() || theProjectile.gameObject.GetComponentInChildren<IDDropBomb>() || theProjectile.gameObject.GetComponentInParent<IDDropBomb>())
  4402. {
  4403.  
  4404.  
  4405. //print("Bomb hit Target Via Bomb Impact- it has: " + currentPartStructure + " Structure");
  4406. IDDropBomb thisBImpact = theProjectile.gameObject.GetComponent<IDDropBomb>();
  4407. if (thisBImpact != null)
  4408. {
  4409. thisBRB = thisBImpact.gameObject.GetComponent<Rigidbody>();
  4410. if (thisBRB == null)
  4411. {
  4412. thisBRB = thisBImpact.gameObject.GetComponentInChildren<Rigidbody>();
  4413. if (thisBRB == null)
  4414. {
  4415. thisBRB = thisBImpact.gameObject.GetComponentInParent<Rigidbody>();
  4416. }
  4417. }
  4418. }
  4419. IDDropBomb thisB2Impact = theProjectile.gameObject.GetComponentInChildren<IDDropBomb>();
  4420. if (thisB2Impact != null)
  4421. {
  4422. thisBRB = thisB2Impact.gameObject.GetComponent<Rigidbody>();
  4423. if (thisBRB == null)
  4424. {
  4425. thisBRB = thisB2Impact.gameObject.GetComponentInChildren<Rigidbody>();
  4426. if (thisBRB == null)
  4427. {
  4428. thisBRB = thisB2Impact.gameObject.GetComponentInParent<Rigidbody>();
  4429. }
  4430. }
  4431. }
  4432. IDDropBomb thisB3Impact = theProjectile.gameObject.GetComponentInParent<IDDropBomb>();
  4433. if (thisB3Impact != null)
  4434. {
  4435. thisBRB = thisB3Impact.gameObject.GetComponent<Rigidbody>();
  4436. if (thisBRB == null)
  4437. {
  4438. thisBRB = thisB3Impact.gameObject.GetComponentInChildren<Rigidbody>();
  4439. if (thisBRB == null)
  4440. {
  4441. thisBRB = thisB3Impact.gameObject.GetComponentInParent<Rigidbody>();
  4442. }
  4443. }
  4444. }
  4445.  
  4446.  
  4447.  
  4448.  
  4449.  
  4450. if (thisBRB.velocity.magnitude > 5f && this.currentPartStructure > 0f && thisB3Impact.septimer > 0.25f)
  4451. {
  4452. FXMonger.Explode(this.part, this.part.transform.position, 0.1f + thisBRB.mass);
  4453. thisB3Impact.terrainHit();
  4454.  
  4455. if (this.vessel != FlightGlobals.ActiveVessel) this.vessel.GoOffRails();
  4456.  
  4457. this.projHardness = thisB3Impact.isHardness;
  4458.  
  4459. this.warheadModifier = thisB3Impact.isWarheadType;
  4460.  
  4461. this.projPenetrate = 400f;
  4462.  
  4463. this.projectileMass = thisBRB.mass;
  4464.  
  4465. this.projectileVelocity = thisBRB.velocity.magnitude;
  4466.  
  4467. this.hitIsTorpedo = thisB3Impact.isTorpedo;
  4468.  
  4469. checkPenetrate();
  4470.  
  4471. Destroy(thisB3Impact.gameObject);
  4472. }
  4473.  
  4474. //}
  4475.  
  4476. }
  4477.  
  4478.  
  4479.  
  4480. }
  4481.  
  4482. public void checkKerbal()
  4483. {
  4484.  
  4485. CrewRoster crewRoster = HighLogic.CurrentGame.CrewRoster;
  4486. ProtoCrewMember getStats = FlightGlobals.ActiveVessel.GetVesselCrew().FirstOrDefault();
  4487. lastKerbalName = getStats.name;
  4488.  
  4489. bool oneTime = true;
  4490.  
  4491.  
  4492. foreach (ProtoCrewMember crewMember in crewRoster)
  4493. {
  4494.  
  4495. if (lastKerbalName == crewMember.name && oneTime == true)
  4496. {
  4497. ourKerbalsStupid = crewMember.stupidity;
  4498. ourKerbalIsBadass = crewMember.isBadass;
  4499. ourKerbalCourage = crewMember.courage;
  4500.  
  4501. string showKerStats = crewMember.name + " has a technicial rating of " + (1f - ourKerbalsStupid);
  4502. ScreenMessages.PostScreenMessage(new ScreenMessage(showKerStats, 3f, ScreenMessageStyle.UPPER_CENTER));
  4503. oneTime = false;
  4504. }
  4505. }
  4506.  
  4507.  
  4508.  
  4509. }
  4510.  
  4511.  
  4512.  
  4513.  
  4514. }
  4515.  
  4516. *****************************************************************Targetpart
  4517.  
  4518. using System;
  4519. using System.Collections.Generic;
  4520. using System.Linq;
  4521. using System.Text;
  4522. using System.Threading.Tasks;
  4523. using UnityEngine;
  4524.  
  4525.  
  4526. public class IDtargeter : InternalModule
  4527. {
  4528.  
  4529. public Vector3 TlocXYZ;
  4530. public Vector3 compareXYZ;
  4531.  
  4532. public Vector3 targScaler;
  4533. public Vector3 compareScale;
  4534.  
  4535. public bool firstRunPersist;
  4536.  
  4537. private bool firstRun = true;
  4538. private bool foundSight = false;
  4539. private bool gunSightOn = true;
  4540.  
  4541. private Transform targeterTransform;
  4542.  
  4543.  
  4544. public void Update()
  4545. {
  4546. if (!HighLogic.LoadedSceneIsFlight) return;
  4547.  
  4548. if (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA || CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.Internal)
  4549. {
  4550.  
  4551. if (foundSight == false)
  4552. {
  4553.  
  4554.  
  4555. try
  4556. {
  4557. this.targeterTransform = internalProp.FindModelTransform("gunSight");
  4558. print("Looking for part with gunSight");
  4559. }
  4560. catch
  4561. {
  4562. print("Finding the gunSight!");
  4563. }
  4564.  
  4565. if (this.targeterTransform != null)
  4566. {
  4567. foundSight = true;
  4568. print("Found a gunSight!");
  4569. }
  4570.  
  4571. }
  4572.  
  4573. if (firstRun == true && this.targeterTransform != null)
  4574. {
  4575. firstRunPersist = this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().firstRunPersistMem;
  4576.  
  4577. TlocXYZ = this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().TlocXYZMem;
  4578. targScaler = this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().targScalerMem;
  4579.  
  4580. if (firstRunPersist == true)
  4581. {
  4582. print("Initialize gunSight for the first time");
  4583. TlocXYZ = new Vector3(-0.08f, 0.35f, -4.81f);
  4584. targScaler = new Vector3(0.036f, 0.036f, 0.036f);
  4585.  
  4586. this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().TlocXYZMem = TlocXYZ;
  4587. this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().targScalerMem = targScaler;
  4588.  
  4589. firstRunPersist = false;
  4590. this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().firstRunPersistMem = firstRunPersist;
  4591. }
  4592.  
  4593. compareXYZ = this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().TlocXYZMem;
  4594. if (this.targeterTransform.position != compareXYZ)
  4595. {
  4596. TlocXYZ = compareXYZ;
  4597. this.targeterTransform.position = TlocXYZ;
  4598. }
  4599.  
  4600. compareScale = this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().targScalerMem;
  4601.  
  4602. if (this.targeterTransform.localScale != compareScale)
  4603. {
  4604. targScaler = compareScale;
  4605. this.targeterTransform.localScale = targScaler;
  4606. }
  4607.  
  4608. firstRun = false;
  4609. }
  4610.  
  4611. if (this.vessel == FlightGlobals.ActiveVessel && this.targeterTransform != null)
  4612. {
  4613.  
  4614. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.DownArrow))
  4615. {
  4616. TlocXYZ.z = TlocXYZ.z + 0.01f;
  4617. this.targeterTransform.position = TlocXYZ;
  4618. this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().TlocXYZMem = TlocXYZ;
  4619. }
  4620. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.UpArrow))
  4621. {
  4622. TlocXYZ.z = TlocXYZ.z - 0.01f;
  4623. this.targeterTransform.position = TlocXYZ;
  4624. this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().TlocXYZMem = TlocXYZ;
  4625. }
  4626. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.RightArrow))
  4627. {
  4628. TlocXYZ.x = TlocXYZ.x + 0.01f;
  4629. this.targeterTransform.position = TlocXYZ;
  4630. this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().TlocXYZMem = TlocXYZ;
  4631. }
  4632. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.LeftArrow))
  4633. {
  4634. TlocXYZ.x = TlocXYZ.x - 0.01f;
  4635. this.targeterTransform.position = TlocXYZ;
  4636. this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().TlocXYZMem = TlocXYZ;
  4637. }
  4638. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.KeypadMultiply))
  4639. {
  4640. TlocXYZ.y = TlocXYZ.y + 0.025f;
  4641. this.targeterTransform.position = TlocXYZ;
  4642. this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().TlocXYZMem = TlocXYZ;
  4643. }
  4644. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.KeypadDivide))
  4645. {
  4646. TlocXYZ.y = TlocXYZ.y - 0.025f;
  4647. this.targeterTransform.position = TlocXYZ;
  4648. this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().TlocXYZMem = TlocXYZ;
  4649. }
  4650.  
  4651.  
  4652. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.KeypadMinus))
  4653. {
  4654. float doScale = targScaler.x;
  4655. doScale = doScale - 0.001f;
  4656. targScaler = new Vector3(doScale, doScale, doScale);
  4657. this.targeterTransform.localScale = targScaler;
  4658. this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().targScalerMem = targScaler;
  4659. print("gunSight Smaller");
  4660. print(TlocXYZ.x + ", " + TlocXYZ.y + ", " + TlocXYZ.z);
  4661. print(targScaler.x + ", " + targScaler.y + ", " + targScaler.z);
  4662. }
  4663. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.KeypadPlus))
  4664. {
  4665. float doScale = targScaler.x;
  4666. doScale = doScale + 0.001f;
  4667. targScaler = new Vector3(doScale, doScale, doScale);
  4668. this.targeterTransform.localScale = targScaler;
  4669. this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault().targScalerMem = targScaler;
  4670. print("gunSight Larger");
  4671. print(TlocXYZ.x + ", " + TlocXYZ.y + ", " + TlocXYZ.z);
  4672. print(targScaler.x + ", " + targScaler.y + ", " + targScaler.z);
  4673. }
  4674.  
  4675. if (gunSightOn == false && Input.GetKeyDown(KeyCode.Insert))
  4676. {
  4677. targeterTransform.GetComponents<MeshRenderer>().FirstOrDefault().enabled = true;
  4678. }
  4679. else if (gunSightOn == true && Input.GetKeyDown(KeyCode.Insert))
  4680. {
  4681. targeterTransform.GetComponents<MeshRenderer>().FirstOrDefault().enabled = false;
  4682. }
  4683. }
  4684.  
  4685.  
  4686. }
  4687. else
  4688. { firstRun = true; }
  4689.  
  4690.  
  4691. }
  4692.  
  4693.  
  4694. }
  4695.  
  4696. public class IDtargeterEXT : PartModule
  4697. {
  4698.  
  4699. public Vector3 TlocXYZ;
  4700. public Vector3 compareXYZ;
  4701.  
  4702. public Vector3 targScaler;
  4703. public Vector3 compareScale;
  4704.  
  4705. public bool firstRunPersist = true;
  4706.  
  4707. private bool firstRun = true;
  4708. private bool foundSight = false;
  4709. private bool gunSightOn = true;
  4710.  
  4711. private Transform targeterTransform;
  4712.  
  4713.  
  4714. public void FixedUpdate()
  4715. {
  4716. if (!HighLogic.LoadedSceneIsFlight) return;
  4717.  
  4718. if (foundSight == false)
  4719. {
  4720.  
  4721.  
  4722. try
  4723. {
  4724. targeterTransform = part.FindModelTransform("gunSight");
  4725. print("Looking for part with gunSight");
  4726. }
  4727. catch
  4728. {
  4729. print("Finding the gunSight!");
  4730. }
  4731.  
  4732. if (targeterTransform != null)
  4733. {
  4734. foundSight = true;
  4735. print("Found a gunSight!");
  4736. }
  4737.  
  4738. }
  4739.  
  4740. if (firstRun == true && foundSight == true)
  4741. {
  4742. cockpitMemory thisMemory = this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault();
  4743. if (thisMemory != null)
  4744. {
  4745. firstRunPersist = thisMemory.firstRunPersistMem;
  4746. }
  4747.  
  4748. print("Initialize gunSight for the first time");
  4749. TlocXYZ = new Vector3(0f, 0f, -9f);
  4750. targeterTransform.localPosition = TlocXYZ;
  4751.  
  4752. targScaler = new Vector3(0.036f, 0.036f, 0.036f);
  4753. print("TlocXYZ = " + TlocXYZ);
  4754.  
  4755. if (firstRunPersist == true)
  4756. {
  4757. thisMemory.TlocXYZMem = TlocXYZ;
  4758. thisMemory.targScalerMem = targScaler;
  4759.  
  4760. print("TlocXYZMem = " + thisMemory.TlocXYZMem);
  4761.  
  4762. firstRunPersist = false;
  4763. thisMemory.firstRunPersistMem = firstRunPersist;
  4764. }
  4765.  
  4766. compareXYZ = thisMemory.TlocXYZMem;
  4767. if (this.targeterTransform.localPosition != compareXYZ)
  4768. {
  4769. TlocXYZ = compareXYZ;
  4770. targeterTransform.localPosition = TlocXYZ;
  4771. }
  4772.  
  4773. compareScale = thisMemory.targScalerMem;
  4774.  
  4775. if (this.targeterTransform.localScale != compareScale)
  4776. {
  4777. targScaler = compareScale;
  4778. targeterTransform.localScale = targScaler;
  4779. }
  4780.  
  4781. firstRun = false;
  4782. }
  4783. else
  4784. { firstRun = true; }
  4785. }
  4786. public void Update()
  4787. {
  4788.  
  4789. if (this.vessel == FlightGlobals.ActiveVessel && this.targeterTransform != null)
  4790. {
  4791. cockpitMemory thisMemory = this.vessel.FindPartModulesImplementing<cockpitMemory>().FirstOrDefault();
  4792.  
  4793.  
  4794.  
  4795. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.DownArrow))
  4796. {
  4797. TlocXYZ.z = TlocXYZ.z + 0.01f;
  4798. this.targeterTransform.localPosition = TlocXYZ;
  4799. thisMemory.TlocXYZMem = TlocXYZ;
  4800. }
  4801. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.UpArrow))
  4802. {
  4803. TlocXYZ.z = TlocXYZ.z - 0.01f;
  4804. this.targeterTransform.localPosition = TlocXYZ;
  4805. thisMemory.TlocXYZMem = TlocXYZ;
  4806. }
  4807. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.RightArrow))
  4808. {
  4809. TlocXYZ.x = TlocXYZ.x + 0.01f;
  4810. this.targeterTransform.localPosition = TlocXYZ;
  4811. thisMemory.TlocXYZMem = TlocXYZ;
  4812. }
  4813. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.LeftArrow))
  4814. {
  4815. TlocXYZ.x = TlocXYZ.x - 0.01f;
  4816. this.targeterTransform.localPosition = TlocXYZ;
  4817. thisMemory.TlocXYZMem = TlocXYZ;
  4818. }
  4819. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.KeypadMultiply))
  4820. {
  4821. TlocXYZ.y = TlocXYZ.y + 0.025f;
  4822. this.targeterTransform.localPosition = TlocXYZ;
  4823. thisMemory.TlocXYZMem = TlocXYZ;
  4824. }
  4825. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.KeypadDivide))
  4826. {
  4827. TlocXYZ.y = TlocXYZ.y - 0.025f;
  4828. this.targeterTransform.localPosition = TlocXYZ;
  4829. thisMemory.TlocXYZMem = TlocXYZ;
  4830. }
  4831.  
  4832.  
  4833. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.KeypadMinus))
  4834. {
  4835. float doScale = targScaler.x;
  4836. doScale = doScale - 0.001f;
  4837. targScaler = new Vector3(doScale, doScale, doScale);
  4838. this.targeterTransform.localScale = targScaler;
  4839. thisMemory.targScalerMem = targScaler;
  4840. print("gunSight Smaller");
  4841. print(TlocXYZ.x + ", " + TlocXYZ.y + ", " + TlocXYZ.z);
  4842. print(targScaler.x + ", " + targScaler.y + ", " + targScaler.z);
  4843. }
  4844. if (Input.GetKey(KeyCode.RightShift) && Input.GetKey(KeyCode.KeypadPlus))
  4845. {
  4846. float doScale = targScaler.x;
  4847. doScale = doScale + 0.001f;
  4848. targScaler = new Vector3(doScale, doScale, doScale);
  4849. this.targeterTransform.localScale = targScaler;
  4850. thisMemory.targScalerMem = targScaler;
  4851. print("gunSight Larger");
  4852. print(TlocXYZ.x + ", " + TlocXYZ.y + ", " + TlocXYZ.z);
  4853. print(targScaler.x + ", " + targScaler.y + ", " + targScaler.z);
  4854. }
  4855.  
  4856. if (gunSightOn == false && Input.GetKeyDown(KeyCode.Insert))
  4857. {
  4858. targeterTransform.GetComponents<MeshRenderer>().FirstOrDefault().enabled = true;
  4859. gunSightOn = true;
  4860. }
  4861. if (gunSightOn == true && Input.GetKey(KeyCode.RightShift) && Input.GetKeyDown(KeyCode.Insert))
  4862. {
  4863. targeterTransform.GetComponents<MeshRenderer>().FirstOrDefault().enabled = false;
  4864. gunSightOn = false;
  4865. }
  4866.  
  4867.  
  4868. }
  4869. }
  4870.  
  4871. }
  4872.  
  4873. public class cockpitMemory : PartModule
  4874. {
  4875. [KSPField(isPersistant = true)]
  4876. public Vector3 TlocXYZMem;
  4877.  
  4878. [KSPField(isPersistant = true)]
  4879. public Vector3 targScalerMem;
  4880.  
  4881. [KSPField(isPersistant = true)]
  4882. public bool firstRunPersistMem = true;
  4883.  
  4884. }
  4885.  
  4886. *******************************************************IDtargeter
  4887.  
  4888. using System;
  4889. using System.Collections.Generic;
  4890. using System.Linq;
  4891. using System.Text;
  4892. using System.Threading.Tasks;
  4893. using UnityEngine;
  4894.  
  4895.  
  4896. public class projectileWS : PartModule
  4897. {
  4898. public bool fireBurst = false;
  4899. public bool proximitySet = false;
  4900.  
  4901. [KSPField(guiActive = true, isPersistant = true)]
  4902. public bool guardMode = false;
  4903.  
  4904. [KSPField(guiActive = true, guiName = "Transfer Mode: ")]
  4905. public bool transferAmmo = false;
  4906.  
  4907. [KSPField(isPersistant = true, guiActiveEditor = false, guiActive = false, guiName = "CIWS Lead: "), UI_FloatRange(minValue = 0f, maxValue = 1f, stepIncrement = 0.025f)]
  4908. public float guiLead = 0.375f;
  4909.  
  4910. [KSPField(guiActive = true, isPersistant = true)]
  4911. public bool ctrlTurret = false;
  4912.  
  4913. [KSPField(guiActive = true, isPersistant = true)]
  4914. public bool invertRotation = false;
  4915.  
  4916. [KSPField(isPersistant = true)]
  4917. public bool isAutoLoader = false;
  4918.  
  4919. public string setIFF = "";
  4920.  
  4921. public bool missileIFFDone = false;
  4922.  
  4923. public GameObject bullet, bulletTwo, bulletThree;
  4924. public GameObject leadTarget;
  4925.  
  4926. public FXGroup soundGroup, soundGroup2, soundGroup3, soundGroup4, soundGroup5, soundGroup6;
  4927.  
  4928. public GameObject fireCannonFX;
  4929. public GameObject burstTrailFX;
  4930. //public GameObject burstFlash;
  4931.  
  4932. private Ray rayLOS;
  4933. public RaycastHit hitLOS;
  4934. public bool fireOverride = false;
  4935. public bool tripOverride = false;
  4936. public Vector3 currentTurretAngle;
  4937. public Vector3 currentTurretLocation;
  4938.  
  4939. private Transform turretTransform;
  4940. private Transform muzzleFlashLight, muzzleFlashLightTwo, muzzleFlashLightThree;
  4941.  
  4942. public bool hostileClosing = false;
  4943. public bool takeOne = false;
  4944.  
  4945. public Vessel hostileOne, hostileTwo, hostileThree, targetHostile;
  4946.  
  4947. [KSPField]
  4948. public float gunType = 0f;
  4949.  
  4950. [KSPField]
  4951. public float turretType = 0f;
  4952.  
  4953. [KSPField]
  4954. public bool isTurret = false;
  4955.  
  4956. [KSPField(isPersistant = true, guiActiveEditor = true, guiActive = true, guiName = "TurrSpd: "), UI_FloatRange(minValue = 0.1f, maxValue = 1f, stepIncrement = 0.1f)]
  4957. public float turretSpeed = 1f;
  4958.  
  4959. [KSPField]
  4960. public bool isCIWS = false;
  4961.  
  4962. [KSPField]
  4963. public float bulletSpawns = 1f;
  4964.  
  4965. [KSPField]
  4966. public float detType = 0f;
  4967.  
  4968. public float ammoBursts = 0f;
  4969.  
  4970. [KSPField]
  4971. public float projectileScale = 0.25f;
  4972.  
  4973. [KSPField]
  4974. public string ammoType = "none";
  4975.  
  4976. [KSPField]
  4977. public float ordHardness = 300f;
  4978.  
  4979. [KSPField(isPersistant = true, guiActiveEditor = true, guiActive = false, guiName = "AmmoType: "), UI_FloatRange(minValue = 0f, maxValue = 3f, stepIncrement = 1f)]
  4980. public float warheadType = 0f;
  4981.  
  4982. [KSPField(guiActiveEditor = true, guiActive = true, guiName = "AmmoType: ")]
  4983. public string warheadShow = "Kinetic";
  4984.  
  4985. [KSPField(guiActiveEditor = false, guiActive = true, guiName = "Elevation: ")]
  4986. public float elevateShow = 0;
  4987.  
  4988. [KSPField]
  4989. public float projKick = 0.45f;
  4990.  
  4991. [KSPField]
  4992. public string animatedPart = "none";
  4993.  
  4994. [KSPField]
  4995. public string animateDir = "X";
  4996.  
  4997. [KSPField]
  4998. public float animateDist = 0.001f;
  4999.  
  5000. private Transform animateTransform;
  5001. private Transform animateDefaultTransform;
  5002. private bool firstRun = true;
  5003. public bool animateMoved = false;
  5004.  
  5005. [KSPField]
  5006. public string animated2Part = "none";
  5007.  
  5008. [KSPField]
  5009. public string animate2Dir = "X";
  5010.  
  5011. [KSPField]
  5012. public float animate2Dist = 0.001f;
  5013.  
  5014. private Transform animate2Transform;
  5015. private Transform animate2DefaultTransform;
  5016.  
  5017. public bool animate2Moved = false;
  5018.  
  5019.  
  5020. public Transform turretBodyRotate;
  5021.  
  5022. public Transform turretBarrelElevation;
  5023.  
  5024. public float origTurretElevation = 0f;
  5025. public float showTurretElevation = 0f;
  5026. public float showTurretRotation = 0f;
  5027.  
  5028. [KSPField(isPersistant = true)]
  5029. public float ammoCap = 0f;
  5030.  
  5031. [KSPField]
  5032. public float rateOfFire = 10f;
  5033.  
  5034. public float origRateOfFire = 10f;
  5035.  
  5036. public float bulletCoolTimer = 10f;
  5037.  
  5038. public float updateAmmoTimer = 30f;
  5039.  
  5040. public float updateGunDirTimer = 300f;
  5041.  
  5042. public float randomBurstTimer = 3f;
  5043.  
  5044. [KSPField]
  5045. public float projMass;
  5046.  
  5047. [KSPField]
  5048. public float projForce;
  5049.  
  5050. [KSPField(isPersistant = true, guiActiveEditor = true, guiActive = true, guiName = "AutoTrack: "), UI_Toggle(controlEnabled = false, disabledText = "No", enabledText = "Yes")]
  5051. public bool autoTrackOn = false;
  5052.  
  5053. [KSPField]
  5054. public bool smartTracking = false;
  5055.  
  5056. public float leadMulti;
  5057.  
  5058. [KSPField(isPersistant=true)]
  5059. public bool hasActiveDirector = false;
  5060.  
  5061. public gunDirector thisGunDirector;
  5062.  
  5063. public float targetDistance = 0f;
  5064.  
  5065. public AnimationCurve shotPrediction;
  5066.  
  5067. [KSPField]
  5068. public float bulletFXChance = 80f;
  5069.  
  5070. [KSPField]
  5071. public float bulletFXLife = 10f;
  5072.  
  5073. [KSPField]
  5074. public float projDrag;
  5075.  
  5076.  
  5077. public float projPenetrate = 0f;
  5078.  
  5079.  
  5080. [KSPEvent(active = true, guiName = "Reload Nearby", guiActiveUnfocused = true, externalToEVAOnly = true, guiActive = false, unfocusedRange = 5f)]
  5081. public void reloadCannon()
  5082. {
  5083. if (this.ammoBursts <= ammoCap)
  5084. {
  5085. float needsAmmo = ammoCap - this.ammoBursts;
  5086. float takeAmmo = 0f;
  5087. bool madeReload = false;
  5088. PartResourceList resourceList = this.part.Resources;
  5089.  
  5090. foreach (Vessel v in FlightGlobals.Vessels)
  5091. {
  5092. if (Vector3.Distance(v.transform.position, this.transform.position) < 40f && v != this.vessel)
  5093. {
  5094. foreach (Part rPart in v.Parts)
  5095. {
  5096. foreach (PartModule rModule in rPart.Modules)
  5097. {
  5098. if(rModule is IDDepot)
  5099. {
  5100. PartResourceList rresourceList = rPart.Resources;
  5101. foreach (PartResource rresource in rresourceList)
  5102. {
  5103. if (rresource.resourceName == ammoType && madeReload == false)
  5104. {
  5105. foreach (PartResource resource in resourceList)
  5106. {
  5107. if (resource.resourceName == ammoType)
  5108. {
  5109. if (rresource.amount > needsAmmo)
  5110. {
  5111. takeAmmo = needsAmmo;
  5112. }
  5113. else takeAmmo = (float)rresource.amount;
  5114.  
  5115. rresource.amount -= (double)takeAmmo;
  5116. resource.amount += (double)takeAmmo;
  5117. ammoBursts = (int)resource.amount;
  5118. ScreenMessages.PostScreenMessage(new ScreenMessage("Found ammoType - adding from: " + v.vesselName, 8f, ScreenMessageStyle.UPPER_CENTER));
  5119. //print("Found ammoType - adding from: " + v.vesselName);
  5120. madeReload = true;
  5121. }
  5122.  
  5123. }
  5124. }
  5125. }
  5126. }
  5127. }
  5128. }
  5129.  
  5130. }
  5131. else if (Vector3.Distance(v.transform.position, this.transform.position) > 40f && Vector3.Distance(v.transform.position, this.transform.position) < 250f)
  5132. {
  5133. //ScreenMessages.PostScreenMessage(new ScreenMessage("There is no vessel within 40m! Move closer!", 4f, ScreenMessageStyle.UPPER_CENTER));
  5134. //print("There is no vessel within 40m! Move closer!");
  5135. }
  5136. }
  5137.  
  5138.  
  5139. }
  5140.  
  5141.  
  5142.  
  5143. }
  5144.  
  5145. [KSPEvent(name = "fireburst", active = true, guiActive = true, guiName = "Fire Burst")]
  5146. public void fireCannonBurst()
  5147. {
  5148. if (this.ammoBursts >= 1f && bulletCoolTimer <= 0f && fireOverride == false && transferAmmo == false)
  5149. {
  5150. //if (this.isTurret == true && turretType == 1f && ctrlTurret == false || ctrlTurret == false) //all now
  5151. //{
  5152. // //Debug.Log("Turret type 1 - no fire - control off!"); // testing, comment out later.
  5153. //}
  5154. //else
  5155. //{
  5156. fireBurst = true;
  5157. fireCannonFX.particleEmitter.emit = true;
  5158. //if (gunType == 0f) burstFlash.SetActive(true);
  5159. #region Turn on lights for muzzle flashes
  5160. if (bulletSpawns == 1)
  5161. {
  5162. this.muzzleFlashLight.GetComponents<Light>().FirstOrDefault().enabled = true;
  5163. }
  5164. else if (bulletSpawns == 2)
  5165. {
  5166. this.muzzleFlashLight.GetComponents<Light>().FirstOrDefault().enabled = true;
  5167. this.muzzleFlashLightTwo.GetComponents<Light>().FirstOrDefault().enabled = true;
  5168. }
  5169. else if (bulletSpawns == 3)
  5170. {
  5171. this.muzzleFlashLight.GetComponents<Light>().FirstOrDefault().enabled = true;
  5172. this.muzzleFlashLightTwo.GetComponents<Light>().FirstOrDefault().enabled = true;
  5173. this.muzzleFlashLightThree.GetComponents<Light>().FirstOrDefault().enabled = true;
  5174. }
  5175. #endregion
  5176. this.ammoBursts = this.ammoBursts - this.bulletSpawns;
  5177.  
  5178. //}
  5179.  
  5180. }
  5181. }
  5182.  
  5183. [KSPEvent(name = "controlthis", active = true, guiActive = true, guiName = "Control This")]
  5184. public void letsControlTurret()
  5185. {
  5186. if (ctrlTurret == false)
  5187. {
  5188. ctrlTurret = true;
  5189.  
  5190. }
  5191. else if (ctrlTurret == true)
  5192. {
  5193. ctrlTurret = false;
  5194. }
  5195. }
  5196.  
  5197. [KSPEvent(name = "xferAmmo", active = true, guiActiveUnfocused = true, externalToEVAOnly = true, guiActive = false, unfocusedRange = 5f, guiName = "Transfer Ammo")]
  5198. public void letsTransferAmmo()
  5199. {
  5200. if (transferAmmo == false)
  5201. {
  5202. transferAmmo = true;
  5203. }
  5204. else if (transferAmmo == true)
  5205. {
  5206. transferAmmo = false;
  5207. }
  5208. }
  5209.  
  5210. [KSPEvent(name = "revrotation", active = true, guiActive = false, guiName = "Reverse Rotation")]
  5211. public void letsRevRotation()
  5212. {
  5213. if (invertRotation == false)
  5214. {
  5215. invertRotation = true;
  5216. }
  5217. else if (invertRotation == true)
  5218. {
  5219. invertRotation = false;
  5220. }
  5221. }
  5222.  
  5223. [KSPAction("Fire Cannon")]
  5224. public void actFireCannon(KSPActionParam param)
  5225. {
  5226. if (param.type == KSPActionType.Activate)
  5227. {
  5228. fireCannonBurst();
  5229. }
  5230. }
  5231.  
  5232.  
  5233. public override void OnStart(PartModule.StartState state)
  5234. {
  5235. if (!HighLogic.LoadedSceneIsFlight) return;
  5236. base.OnStart(state);
  5237. bulletCoolTimer = rateOfFire;
  5238. origRateOfFire = rateOfFire;
  5239. #region Set muzzle flash locations
  5240. if (bulletSpawns == 1)
  5241. {
  5242. this.muzzleFlashLight = part.FindModelTransform("mFlash");
  5243. this.muzzleFlashLight.GetComponents<Light>().FirstOrDefault().enabled = false; //starts off!
  5244. }
  5245. else if (bulletSpawns == 2)
  5246. {
  5247. this.muzzleFlashLight = part.FindModelTransform("mFlash");
  5248. this.muzzleFlashLight.GetComponents<Light>().FirstOrDefault().enabled = false; //starts off!
  5249. this.muzzleFlashLightTwo = part.FindModelTransform("mFlashTwo");
  5250. this.muzzleFlashLightTwo.GetComponents<Light>().FirstOrDefault().enabled = false; //starts off!
  5251. }
  5252. else if (bulletSpawns == 3)
  5253. {
  5254. this.muzzleFlashLight = part.FindModelTransform("mFlash");
  5255. this.muzzleFlashLight.GetComponents<Light>().FirstOrDefault().enabled = false; //starts off!
  5256. this.muzzleFlashLightTwo = part.FindModelTransform("mFlashTwo");
  5257. this.muzzleFlashLightTwo.GetComponents<Light>().FirstOrDefault().enabled = false; //starts off!
  5258. this.muzzleFlashLightThree = part.FindModelTransform("mFlashThree");
  5259. this.muzzleFlashLightThree.GetComponents<Light>().FirstOrDefault().enabled = false; //starts off!
  5260. }
  5261. #endregion
  5262.  
  5263. leadTarget = GameObject.CreatePrimitive(PrimitiveType.Cube);
  5264. leadTarget.SetActive(false);
  5265. leadTarget.renderer.enabled = false;
  5266. Destroy(leadTarget.rigidbody);
  5267. leadTarget.collider.enabled = false;
  5268.  
  5269.  
  5270.  
  5271.  
  5272. if (turretType == 0 && isTurret == true)
  5273. {
  5274. turretTransform = part.FindModelTransform("Turret");
  5275. }
  5276.  
  5277. if (turretType == 1 && isTurret == true)
  5278. {
  5279. turretBodyRotate = part.FindModelTransform("turretBody");
  5280. turretBarrelElevation = part.FindModelTransform("turretElevator");
  5281. origTurretElevation = turretBarrelElevation.eulerAngles.z;
  5282. //Events["letsControlTurret"].guiActive = true;
  5283. //Events["letsRevRotation"].guiActive = true;
  5284. }
  5285.  
  5286. if (isAutoLoader == true)
  5287. {
  5288. Events["letsTransferAmmo"].guiActive = true;
  5289. }
  5290.  
  5291. #region Pull IFF
  5292. if(this.setIFF == "")
  5293. {
  5294.  
  5295. foreach (Part p in vessel.parts)
  5296. {
  5297. PartModule m = p.GetComponent<PartModule>();
  5298. if (m is relayIFF)
  5299. {
  5300. relayIFF checkIFF = m.GetComponent<relayIFF>();
  5301. this.setIFF = checkIFF.setIFF;
  5302. }
  5303.  
  5304.  
  5305. }
  5306. }
  5307.  
  5308. #endregion
  5309.  
  5310.  
  5311. #region Sound effects
  5312.  
  5313.  
  5314.  
  5315. if (!GameDatabase.Instance.ExistsAudioClip("IDSkillfulR1/Sounds/fastBurst") || !GameDatabase.Instance.ExistsAudioClip("IDSkillfulR1/Sounds/singleCannon") || !GameDatabase.Instance.ExistsAudioClip("IDSkillfulR1/Sounds/IDinternalMG") || !GameDatabase.Instance.ExistsAudioClip("IDSkillfulR1/Sounds/largeCannon")) return;
  5316. soundGroup.audio = gameObject.AddComponent<AudioSource>();
  5317. soundGroup2.audio = gameObject.AddComponent<AudioSource>();
  5318. soundGroup3.audio = gameObject.AddComponent<AudioSource>();
  5319. soundGroup4.audio = gameObject.AddComponent<AudioSource>();
  5320. soundGroup5.audio = gameObject.AddComponent<AudioSource>();
  5321. soundGroup6.audio = gameObject.AddComponent<AudioSource>();
  5322.  
  5323.  
  5324.  
  5325. #region machineGun
  5326. if (soundGroup.audio != null && gunType == 3)
  5327. {
  5328. soundGroup.audio.volume = GameSettings.SHIP_VOLUME;
  5329. soundGroup.audio.rolloffMode = AudioRolloffMode.Linear;
  5330. soundGroup.audio.dopplerLevel = 0f;
  5331. soundGroup.audio.panLevel = 1f;
  5332. soundGroup.audio.clip = GameDatabase.Instance.GetAudioClip("IDSkillfulR1/Sounds/IDinternalMG");
  5333. soundGroup.audio.loop = false;
  5334. soundGroup.audio.playOnAwake = false;
  5335. soundGroup.audio.priority = 1;
  5336. }
  5337. if (soundGroup2.audio != null && gunType == 3)
  5338. {
  5339. soundGroup2.audio.volume = GameSettings.SHIP_VOLUME;
  5340. soundGroup2.audio.rolloffMode = AudioRolloffMode.Linear;
  5341. soundGroup2.audio.dopplerLevel = 0f;
  5342. soundGroup2.audio.panLevel = 1f;
  5343. soundGroup2.audio.clip = GameDatabase.Instance.GetAudioClip("IDSkillfulR1/Sounds/IDinternalMG");
  5344. soundGroup2.audio.loop = false;
  5345. soundGroup2.audio.playOnAwake = false;
  5346. soundGroup2.audio.priority = 2;
  5347. }
  5348. if (soundGroup3.audio != null && gunType == 3)
  5349. {
  5350. soundGroup3.audio.volume = GameSettings.SHIP_VOLUME;
  5351. soundGroup3.audio.rolloffMode = AudioRolloffMode.Linear;
  5352. soundGroup3.audio.dopplerLevel = 0f;
  5353. soundGroup3.audio.panLevel = 1f;
  5354. soundGroup3.audio.clip = GameDatabase.Instance.GetAudioClip("IDSkillfulR1/Sounds/IDinternalMG");
  5355. soundGroup3.audio.loop = false;
  5356. soundGroup3.audio.playOnAwake = false;
  5357. soundGroup3.audio.priority = 3;
  5358. }
  5359. if (soundGroup4.audio != null && gunType == 3)
  5360. {
  5361. soundGroup4.audio.volume = GameSettings.SHIP_VOLUME;
  5362. soundGroup4.audio.rolloffMode = AudioRolloffMode.Linear;
  5363. soundGroup4.audio.dopplerLevel = 0f;
  5364. soundGroup4.audio.panLevel = 1f;
  5365. soundGroup4.audio.clip = GameDatabase.Instance.GetAudioClip("IDSkillfulR1/Sounds/IDinternalMG");
  5366. soundGroup4.audio.loop = false;
  5367. soundGroup4.audio.playOnAwake = false;
  5368. soundGroup4.audio.priority = 4;
  5369. }
  5370. if (soundGroup5.audio != null && gunType == 3)
  5371. {
  5372. soundGroup5.audio.volume = GameSettings.SHIP_VOLUME;
  5373. soundGroup5.audio.rolloffMode = AudioRolloffMode.Linear;
  5374. soundGroup5.audio.dopplerLevel = 0f;
  5375. soundGroup5.audio.panLevel = 1f;
  5376. soundGroup5.audio.clip = GameDatabase.Instance.GetAudioClip("IDSkillfulR1/Sounds/IDinternalMG");
  5377. soundGroup5.audio.loop = false;
  5378. soundGroup5.audio.playOnAwake = false;
  5379. soundGroup5.audio.priority = 5;
  5380. }
  5381. if (soundGroup6.audio != null && gunType == 3)
  5382. {
  5383. soundGroup6.audio.volume = GameSettings.SHIP_VOLUME;
  5384. soundGroup6.audio.rolloffMode = AudioRolloffMode.Linear;
  5385. soundGroup6.audio.dopplerLevel = 0f;
  5386. soundGroup6.audio.panLevel = 1f;
  5387. soundGroup6.audio.clip = GameDatabase.Instance.GetAudioClip("IDSkillfulR1/Sounds/IDinternalMG");
  5388. soundGroup6.audio.loop = false;
  5389. soundGroup6.audio.playOnAwake = false;
  5390. soundGroup6.audio.priority = 6;
  5391. }
  5392. #endregion
  5393.  
  5394.  
  5395.  
  5396. if (soundGroup.audio != null && gunType == 2)
  5397. {
  5398. soundGroup.audio.volume = GameSettings.SHIP_VOLUME;
  5399. soundGroup.audio.rolloffMode = AudioRolloffMode.Linear;
  5400. soundGroup.audio.dopplerLevel = 0f;
  5401. soundGroup.audio.panLevel = 1f;
  5402. soundGroup.audio.clip = GameDatabase.Instance.GetAudioClip("IDSkillfulR1/Sounds/fastBurst");
  5403. soundGroup.audio.loop = false;
  5404. soundGroup.audio.playOnAwake = false;
  5405. soundGroup.audio.priority = 1;
  5406. }
  5407.  
  5408. if (soundGroup.audio != null && gunType == 1)
  5409. {
  5410. soundGroup.audio.volume = GameSettings.SHIP_VOLUME;
  5411. soundGroup.audio.rolloffMode = AudioRolloffMode.Linear;
  5412. soundGroup.audio.dopplerLevel = 0f;
  5413. soundGroup.audio.panLevel = 1f;
  5414. soundGroup.audio.clip = GameDatabase.Instance.GetAudioClip("IDSkillfulR1/Sounds/singleCannon");
  5415. soundGroup.audio.loop = false;
  5416. soundGroup.audio.playOnAwake = false;
  5417. soundGroup.audio.priority = 1;
  5418. }
  5419.  
  5420. if (soundGroup.audio != null && gunType == 0)
  5421. {
  5422. soundGroup.audio.volume = GameSettings.SHIP_VOLUME;
  5423. soundGroup.audio.rolloffMode = AudioRolloffMode.Linear;
  5424. soundGroup.audio.dopplerLevel = 0f;
  5425. soundGroup.audio.panLevel = 1f;
  5426. soundGroup.audio.clip = GameDatabase.Instance.GetAudioClip("IDSkillfulR1/Sounds/largeCannon");//change later
  5427. soundGroup.audio.loop = false;
  5428. soundGroup.audio.playOnAwake = false;
  5429. soundGroup.audio.priority = 1;
  5430. }
  5431.  
  5432. #endregion
  5433.  
  5434. #region Particle Effects
  5435. fireCannonFX = (GameObject)GameObject.Instantiate(UnityEngine.Resources.Load("Effects/fx_smokeTrail_light"));
  5436. fireCannonFX.particleEmitter.emit = false;
  5437. fireCannonFX.transform.parent = (muzzleFlashLight.transform);
  5438. fireCannonFX.transform.localPosition = new Vector3(0, 0, 0.2f);
  5439. fireCannonFX.transform.localRotation = this.part.transform.rotation;
  5440. fireCannonFX.particleEmitter.useWorldSpace = true;
  5441. fireCannonFX.particleEmitter.minSize = 1f;
  5442. fireCannonFX.particleEmitter.maxSize = 3f;
  5443. fireCannonFX.particleEmitter.localVelocity = new Vector3(0, 0, 1.5f);
  5444. fireCannonFX.particleEmitter.maxEnergy = 7f;
  5445. fireCannonFX.particleEmitter.minEmission = 120f;
  5446. fireCannonFX.particleEmitter.angularVelocity = 0.01f;
  5447. fireCannonFX.particleEmitter.rndRotation = false;
  5448.  
  5449. //if (burstFlash == null && this.gunType == 0f)
  5450. //{
  5451.  
  5452. // try
  5453. // {
  5454.  
  5455. // burstFlash = GameDatabase.Instance.GetModel("IDSkillfulR1/Effects/largeBlast/model");
  5456. // }
  5457. // catch
  5458. // {
  5459. // print("Problem locating largeBlast FX!");
  5460. // }
  5461.  
  5462. // if (burstFlash != null)
  5463. // {
  5464. // Transform barrel1Blast = part.FindModelTransform("spawnBullet");
  5465.  
  5466. // burstFlash.SetActive(false);
  5467. // burstFlash.transform.position = barrel1Blast.position;
  5468. // burstFlash.transform.parent = barrel1Blast;
  5469. // burstFlash.transform.localRotation = barrel1Blast.localRotation;
  5470.  
  5471. // burstFlash.gameObject.layer = 0;
  5472.  
  5473. // }
  5474.  
  5475. //}
  5476.  
  5477. #endregion
  5478. }
  5479.  
  5480. public override void OnAwake()
  5481. {
  5482. base.OnAwake();
  5483. if (turretType == 0 && isTurret == true)
  5484. {
  5485. turretTransform = part.FindModelTransform("Turret");
  5486. }
  5487.  
  5488. if (turretType == 1 && isTurret == true)
  5489. {
  5490. turretBodyRotate = part.FindModelTransform("turretBody");
  5491. turretBarrelElevation = part.FindModelTransform("turretElevator");
  5492. Events["letsControlTurret"].guiActive = true;
  5493. }
  5494.  
  5495.  
  5496.  
  5497. }
  5498.  
  5499. public void Update()
  5500. {
  5501. if (!HighLogic.LoadedSceneIsFlight) return;
  5502.  
  5503. if (Input.GetKey(KeyCode.Home) && this.vessel == FlightGlobals.ActiveVessel)
  5504. {
  5505. if (this.ammoBursts >= 1f && bulletCoolTimer <= 0f && fireOverride == false && transferAmmo == false)
  5506. {
  5507. if (this.isTurret == true && turretType == 1f && ctrlTurret == false || ctrlTurret == false) //all now
  5508. {
  5509. //Debug.Log("Turret type 1 - no fire - control off!");
  5510. }
  5511. else
  5512. {
  5513. fireBurst = true;
  5514. fireCannonFX.particleEmitter.emit = true;
  5515. //if(gunType == 0f) burstFlash.SetActive(true);
  5516. #region Turn on lights for muzzle flashes
  5517. if (bulletSpawns == 1)
  5518. {
  5519. this.muzzleFlashLight.GetComponents<Light>().FirstOrDefault().enabled = true;
  5520. }
  5521. else if (bulletSpawns == 2)
  5522. {
  5523. this.muzzleFlashLight.GetComponents<Light>().FirstOrDefault().enabled = true;
  5524. this.muzzleFlashLightTwo.GetComponents<Light>().FirstOrDefault().enabled = true;
  5525. }
  5526. else if (bulletSpawns == 3)
  5527. {
  5528. this.muzzleFlashLight.GetComponents<Light>().FirstOrDefault().enabled = true;
  5529. this.muzzleFlashLightTwo.GetComponents<Light>().FirstOrDefault().enabled = true;
  5530. this.muzzleFlashLightThree.GetComponents<Light>().FirstOrDefault().enabled = true;
  5531. }
  5532. #endregion
  5533. this.ammoBursts = this.ammoBursts - this.bulletSpawns;
  5534. }
  5535.  
  5536.  
  5537. }
  5538. }
  5539.  
  5540. }
  5541.  
  5542. public void FixedUpdate()
  5543. {
  5544. #region attach to rotating part
  5545.  
  5546.  
  5547.  
  5548. #endregion
  5549.  
  5550.  
  5551. if (warheadType == 0f) warheadShow = "Kinetic";
  5552. if (warheadType == 1f) warheadShow = "HE";
  5553. if (warheadType == 2f)
  5554. {
  5555. warheadShow = "Incend";
  5556. ordHardness = 220f;
  5557. }
  5558. if (warheadType == 3f) warheadShow = "AP";
  5559.  
  5560. if (turretType == 0f && isTurret == true)
  5561. {
  5562. Fields["guiLead"].guiActive = true;
  5563. Fields["guiLead"].guiActiveEditor = true;
  5564. Fields["invertRotation"].guiActive = false;
  5565. Fields["invertRotation"].guiActiveEditor = false;
  5566. Fields["turretSpeed"].guiActive = false;
  5567. Fields["turretSpeed"].guiActiveEditor = false;
  5568. Fields["elevateShow"].guiActive = false;
  5569. Fields["elevateShow"].guiActiveEditor = false;
  5570. }
  5571. if (turretType == 1f && isTurret == true)
  5572. {
  5573. Fields["guiLead"].guiActive = false;
  5574. Fields["guiLead"].guiActiveEditor = false;
  5575. Fields["guardMode"].guiActive = false;
  5576. Fields["guardMode"].guiActiveEditor = false;
  5577. Fields["autoTrackOn"].guiActive = false;
  5578. Fields["autoTrackOn"].guiActiveEditor = false;
  5579. elevateShow = showTurretElevation;
  5580. }
  5581. if (isTurret == false)
  5582. {
  5583.  
  5584. Fields["elevateShow"].guiActive = false;
  5585. Fields["elevateShow"].guiActiveEditor = false;
  5586. Fields["guiLead"].guiActive = false;
  5587. Fields["guiLead"].guiActiveEditor = false;
  5588. Fields["ctrlTurret"].guiActive = true;
  5589. Fields["ctrlTurret"].guiActiveEditor = true;
  5590. Fields["invertRotation"].guiActive = false;
  5591. Fields["invertRotation"].guiActiveEditor = false;
  5592. Fields["turretSpeed"].guiActive = false;
  5593. Fields["turretSpeed"].guiActiveEditor = false;
  5594. Fields["guardMode"].guiActive = false;
  5595. Fields["guardMode"].guiActiveEditor = false;
  5596. Fields["autoTrackOn"].guiActive = false;
  5597. Fields["autoTrackOn"].guiActiveEditor = false;
  5598. }
  5599.  
  5600. if (HighLogic.LoadedSceneIsFlight)
  5601. {
  5602.  
  5603. autoTracker();
  5604. if (turretType == 0 && isTurret == true)
  5605. {
  5606. safetyLOS();
  5607. }
  5608. if (firstRun == true)
  5609. {
  5610. PartResourceList resourceList = this.part.Resources;
  5611. foreach (PartResource resource in resourceList)
  5612. {
  5613. if (resource.resourceName == ammoType)
  5614. {
  5615.  
  5616. ammoBursts = (int)resource.amount;
  5617. //print("Found " + resource.resourceName + " : " + ammoBursts);
  5618. }
  5619. }
  5620.  
  5621. if (ammoType == "762mmAmmo") projPenetrate = 1.75f;
  5622. if (ammoType == "30calAmmo") projPenetrate = 2f;
  5623. if (ammoType == "50calAmmo") projPenetrate = 2.5f;
  5624. if (ammoType == "30mmAmmo") projPenetrate = 6f;
  5625. if (ammoType == "5inchAmmo") projPenetrate = 66f;
  5626. if (ammoType == "14inchAmmo") projPenetrate = 100f;
  5627.  
  5628.  
  5629. if (animatedPart != "none")
  5630. {
  5631. //print("Initialize the animatePart code");
  5632. animateTransform = part.FindModelTransform(animatedPart);
  5633. if (animateTransform != null && firstRun == true)
  5634. {
  5635. animateDefaultTransform = new GameObject().transform;
  5636. animateDefaultTransform = animateTransform;
  5637. animateDefaultTransform.localPosition = animateTransform.localPosition;
  5638.  
  5639. //print("animatePart found and set!");
  5640. }
  5641. }
  5642. if (animated2Part != "none")
  5643. {
  5644. //print("Initialize the animate2Part code");
  5645. animate2Transform = part.FindModelTransform(animated2Part);
  5646. if (animate2Transform != null && firstRun == true)
  5647. {
  5648. animate2DefaultTransform = new GameObject().transform;
  5649. animate2DefaultTransform = animate2Transform;
  5650. animate2DefaultTransform.localPosition = animate2Transform.localPosition;
  5651.  
  5652. //print("animate2Part found and set!");
  5653. }
  5654. }
  5655.  
  5656. if (turretType == 1 && isTurret == true)
  5657. {
  5658. origTurretElevation = turretBarrelElevation.rotation.Pitch();
  5659. if (this.vessel.isActiveVessel)
  5660. {
  5661. checkGunDirector();
  5662. }
  5663.  
  5664. }
  5665.  
  5666. firstRun = false;
  5667. }
  5668.  
  5669. if (updateGunDirTimer > 0f && this.vessel.isActiveVessel)
  5670. {
  5671. updateGunDirTimer--;
  5672.  
  5673. if (updateGunDirTimer <= 0f)
  5674. {
  5675. checkGunDirector();
  5676.  
  5677. updateGunDirTimer = 300f;
  5678. }
  5679. }
  5680.  
  5681.  
  5682. if (updateAmmoTimer > 0f)
  5683. {
  5684. updateAmmoTimer--;
  5685.  
  5686. if (updateAmmoTimer <= 0f)
  5687. {
  5688. //if (burstFlash != null)
  5689. //{
  5690. // if (burstFlash.activeInHierarchy == true)
  5691. // {
  5692. // burstFlash.SetActive(false);
  5693. // }
  5694. //}
  5695.  
  5696. PartResourceList resourceList = this.part.Resources;
  5697. foreach (PartResource resource in resourceList)
  5698. {
  5699. if (resource.resourceName == ammoType)
  5700. {
  5701. if (transferAmmo == false)
  5702. {
  5703. resource.amount = ammoBursts;
  5704. }
  5705. else ammoBursts = (float)resource.amount;
  5706. }
  5707. }
  5708. updateAmmoTimer = 30f;
  5709. }
  5710.  
  5711. }
  5712.  
  5713. if (bulletCoolTimer > 0f)
  5714. {
  5715. bulletCoolTimer--;
  5716.  
  5717. }
  5718. else
  5719. {
  5720. if (animateTransform != null && animateMoved == true)
  5721. {
  5722.  
  5723. if (animateDir == "Y")
  5724. {
  5725. animateTransform.localPosition = animateTransform.localPosition - new Vector3(0f, animateDist, 0f);
  5726. }
  5727. if (animateDir == "X")
  5728. {
  5729. animateTransform.localPosition = animateTransform.localPosition - new Vector3(animateDist, 0f, 0f);
  5730. }
  5731. if (animateDir == "Z")
  5732. {
  5733. animateTransform.localPosition = animateTransform.localPosition - new Vector3(0f, 0f, animateDist);
  5734. }
  5735. animateMoved = false;
  5736. }
  5737. if (animate2Transform != null && animate2Moved == true)
  5738. {
  5739.  
  5740. if (animate2Dir == "Y")
  5741. {
  5742. animate2Transform.localPosition = animate2Transform.localPosition - new Vector3(0f, animate2Dist, 0f);
  5743. }
  5744. if (animate2Dir == "X")
  5745. {
  5746. animate2Transform.localPosition = animate2Transform.localPosition - new Vector3(animate2Dist, 0f, 0f);
  5747. }
  5748. if (animate2Dir == "Z")
  5749. {
  5750. animate2Transform.localPosition = animate2Transform.localPosition - new Vector3(0f, 0f, animate2Dist);
  5751. }
  5752. animate2Moved = false;
  5753. }
  5754. }
  5755.  
  5756. if (fireBurst == true)
  5757. {
  5758. if (soundGroup.audio.isPlaying == false)
  5759. {
  5760. soundGroup.audio.Play();
  5761. }
  5762. else if (soundGroup2.audio.isPlaying == false)
  5763. {
  5764. soundGroup2.audio.Play();
  5765. }
  5766. else if (soundGroup3.audio.isPlaying == false)
  5767. {
  5768. soundGroup3.audio.Play();
  5769. }
  5770. else if (soundGroup4.audio.isPlaying == false)
  5771. {
  5772. soundGroup4.audio.Play();
  5773. }
  5774. else if (soundGroup5.audio.isPlaying == false)
  5775. {
  5776. soundGroup5.audio.Play();
  5777. }
  5778. else if (soundGroup6.audio.isPlaying == false)
  5779. {
  5780. soundGroup6.audio.Play();
  5781. }
  5782.  
  5783. if (animateTransform != null && animateTransform.localPosition == animateDefaultTransform.localPosition)
  5784. {
  5785. if (animateDir == "Y")
  5786. {
  5787. animateTransform.localPosition = animateTransform.localPosition + new Vector3(0f, animateDist, 0f);
  5788. }
  5789. if (animateDir == "X")
  5790. {
  5791. animateTransform.localPosition = animateTransform.localPosition + new Vector3(animateDist, 0f, 0f);
  5792. }
  5793. if (animateDir == "Z")
  5794. {
  5795. animateTransform.localPosition = animateTransform.localPosition + new Vector3(0f, 0f, animateDist);
  5796. }
  5797. animateMoved = true;
  5798. }
  5799.  
  5800. if (animate2Transform != null && animate2Transform.localPosition == animate2DefaultTransform.localPosition)
  5801. {
  5802. if (animate2Dir == "Y")
  5803. {
  5804. animate2Transform.localPosition = animate2Transform.localPosition + new Vector3(0f, animate2Dist, 0f);
  5805. }
  5806. if (animate2Dir == "X")
  5807. {
  5808. animate2Transform.localPosition = animate2Transform.localPosition + new Vector3(animate2Dist, 0f, 0f);
  5809. }
  5810. if (animate2Dir == "Z")
  5811. {
  5812. animate2Transform.localPosition = animate2Transform.localPosition + new Vector3(0f, 0f, animate2Dist);
  5813. }
  5814. animate2Moved = true;
  5815. }
  5816.  
  5817. placeBulletEvent();
  5818.  
  5819. fireBurst = false;
  5820. }
  5821.  
  5822. if (this.vessel != FlightGlobals.ActiveVessel && turretType == 0 && isTurret == true)
  5823. {
  5824. guardMode = true;
  5825. }
  5826. if (this.vessel == FlightGlobals.ActiveVessel && turretType == 0 && isTurret == true)
  5827. {
  5828. guardMode = false;
  5829. }
  5830.  
  5831. }
  5832. }
  5833.  
  5834. public void placeBulletEvent()
  5835. {
  5836.  
  5837. bullet = GameObject.CreatePrimitive(PrimitiveType.Cube);
  5838. bullet.gameObject.transform.localScale.Set(projectileScale, projectileScale, projectileScale);
  5839. bullet.SetActive(true);
  5840. bullet.renderer.enabled = false;
  5841.  
  5842. if (autoTrackOn == true && turretType == 0 && isTurret == true)
  5843. {
  5844. Transform placeItHere = (transform.Find("model/Rotator/Turret/spawnBullet"));
  5845. bullet.transform.position = placeItHere.position;
  5846. bullet.transform.rotation = placeItHere.rotation;
  5847. bullet.transform.rotation *= Quaternion.Euler(90, 0, 0);
  5848. }
  5849. else if (autoTrackOn == false && turretType != 1 || isTurret == false)
  5850. {
  5851. Transform placeItHere = (transform.Find("model/spawnBullet"));
  5852. bullet.transform.position = placeItHere.position;
  5853. bullet.transform.rotation = placeItHere.rotation;
  5854. }
  5855.  
  5856. #region Turret Multi Barrel
  5857. if (turretType == 1)
  5858. {
  5859. if (bulletSpawns == 1)
  5860. {
  5861. Transform placeItHere = part.FindModelTransform("spawnBullet");
  5862. bullet.transform.position = placeItHere.position;
  5863. bullet.transform.rotation = placeItHere.rotation;
  5864. }
  5865. if (bulletSpawns == 2)
  5866. {
  5867. Transform placeItHere = (transform.Find("model/Turret/turretBody/turretElevator/spawnBullet"));
  5868. bullet.transform.position = placeItHere.position;
  5869. bullet.transform.rotation = placeItHere.rotation;
  5870. bullet.transform.rotation *= Quaternion.Euler(0f, 0f, 0f);
  5871.  
  5872. bulletTwo = GameObject.CreatePrimitive(PrimitiveType.Cube);
  5873. bulletTwo.SetActive(true);
  5874. bulletTwo.renderer.enabled = false;
  5875.  
  5876. Transform placeItHereTwo = (transform.Find("model/Turret/turretBody/turretElevator/spawnBulletTwo"));
  5877. bulletTwo.transform.position = placeItHereTwo.position;
  5878. bulletTwo.transform.rotation = placeItHereTwo.rotation;
  5879.  
  5880. Rigidbody rbTwo = bulletTwo.AddComponent<Rigidbody>();
  5881. rbTwo.collider.enabled = true;
  5882. rbTwo.collider.isTrigger = true;
  5883. rbTwo.useGravity = true;
  5884. rbTwo.detectCollisions = true;
  5885. rbTwo.collisionDetectionMode = CollisionDetectionMode.Continuous;
  5886. rbTwo.mass = projMass;
  5887. rbTwo.drag = projDrag;
  5888. rbTwo.velocity = this.vessel.rigidbody.velocity;
  5889. rbTwo.AddForce(rbTwo.transform.up * projForce, ForceMode.Impulse);
  5890. impact imp2 = bulletTwo.AddComponent<impact>();
  5891. imp2.useHardness = this.ordHardness;
  5892. imp2.useWarheadType = this.warheadType;
  5893. imp2.useProjPenetrate = this.projPenetrate;
  5894. imp2.bulletHoleChance = bulletFXChance;
  5895. imp2.bulletHoleTime = bulletFXLife;
  5896. imp2.wasDirected = hasActiveDirector;
  5897. burstTrailFX = (GameObject)GameObject.Instantiate(UnityEngine.Resources.Load("Effects/fx_exhaustFlame_yellow_tiny"));
  5898. burstTrailFX.particleEmitter.emit = true;
  5899. burstTrailFX.transform.parent = (bulletTwo.transform);
  5900. burstTrailFX.transform.localPosition = new Vector3(0, 0, 0);
  5901. burstTrailFX.transform.rotation = bulletTwo.transform.rotation;
  5902. burstTrailFX.particleEmitter.useWorldSpace = false;
  5903. burstTrailFX.particleEmitter.minSize = 0.3f;
  5904. burstTrailFX.particleEmitter.maxSize = 0.3f;
  5905. burstTrailFX.particleEmitter.localVelocity = new Vector3(0, 0, 0);
  5906. burstTrailFX.particleEmitter.minEnergy = 15f;
  5907. burstTrailFX.particleEmitter.maxEnergy = 15f;
  5908. burstTrailFX.particleEmitter.minEmission = 35f;
  5909. burstTrailFX.particleEmitter.maxEmission = 35f;
  5910. burstTrailFX.particleEmitter.angularVelocity = 0.01f;
  5911. burstTrailFX.particleEmitter.rndRotation = false;
  5912.  
  5913. this.rigidbody.AddForce(-muzzleFlashLight.up * (projForce * projKick), ForceMode.Impulse);
  5914.  
  5915. Destroy(burstTrailFX.gameObject, 1.25f);
  5916.  
  5917. if (gunType == 3) Destroy(bulletTwo.gameObject, 4f);
  5918. if (gunType == 2) Destroy(bulletTwo.gameObject, 4f);
  5919. if (gunType == 1) Destroy(bulletTwo.gameObject, 7f);
  5920. if (gunType == 0) Destroy(bulletTwo.gameObject, 95f);
  5921.  
  5922. this.muzzleFlashLightTwo.GetComponents<Light>().FirstOrDefault().enabled = false;
  5923. }
  5924.  
  5925. if (bulletSpawns == 3)
  5926. {
  5927. Transform placeItHere = (transform.Find("model/Turret/turretBody/turretElevator/spawnBullet"));
  5928. bullet.transform.position = placeItHere.position;
  5929. bullet.transform.rotation = placeItHere.rotation;
  5930. bullet.transform.rotation *= Quaternion.Euler(0f, 0f, 0f);
  5931.  
  5932. bulletTwo = GameObject.CreatePrimitive(PrimitiveType.Cube);
  5933. bulletTwo.SetActive(true);
  5934. bulletTwo.renderer.enabled = false;
  5935.  
  5936. Transform placeItHereTwo = (transform.Find("model/Turret/turretBody/turretElevator/spawnBulletTwo"));
  5937. bulletTwo.transform.position = placeItHereTwo.position;
  5938. bulletTwo.transform.rotation = placeItHereTwo.rotation;
  5939.  
  5940. Rigidbody rbTwo = bulletTwo.AddComponent<Rigidbody>();
  5941. rbTwo.collider.enabled = true;
  5942. rbTwo.collider.isTrigger = true;
  5943. rbTwo.useGravity = true;
  5944. rbTwo.detectCollisions = true;
  5945. rbTwo.collisionDetectionMode = CollisionDetectionMode.Continuous;
  5946. rbTwo.mass = projMass;
  5947. rbTwo.drag = projDrag;
  5948. rbTwo.velocity = this.vessel.rigidbody.velocity;
  5949. rbTwo.AddForce(rbTwo.transform.up * projForce, ForceMode.Impulse);
  5950. impact imp2 = bulletTwo.AddComponent<impact>();
  5951. imp2.useHardness = this.ordHardness;
  5952. imp2.useWarheadType = this.warheadType;
  5953. imp2.useProjPenetrate = this.projPenetrate;
  5954. imp2.bulletHoleChance = bulletFXChance;
  5955. imp2.bulletHoleTime = bulletFXLife;
  5956. imp2.wasDirected = hasActiveDirector;
  5957. burstTrailFX = (GameObject)GameObject.Instantiate(UnityEngine.Resources.Load("Effects/fx_exhaustFlame_yellow_tiny"));
  5958. burstTrailFX.particleEmitter.emit = true;
  5959. burstTrailFX.transform.parent = (bulletTwo.transform);
  5960. burstTrailFX.transform.localPosition = new Vector3(0, 0, 0);
  5961. burstTrailFX.transform.rotation = bulletTwo.transform.rotation;
  5962. burstTrailFX.particleEmitter.useWorldSpace = false;
  5963. burstTrailFX.particleEmitter.minSize = 0.3f;
  5964. burstTrailFX.particleEmitter.maxSize = 0.3f;
  5965. burstTrailFX.particleEmitter.localVelocity = new Vector3(0, 0, 0);
  5966. burstTrailFX.particleEmitter.minEnergy = 15f;
  5967. burstTrailFX.particleEmitter.maxEnergy = 15f;
  5968. burstTrailFX.particleEmitter.minEmission = 35f;
  5969. burstTrailFX.particleEmitter.maxEmission = 35f;
  5970. burstTrailFX.particleEmitter.angularVelocity = 0.01f;
  5971. burstTrailFX.particleEmitter.rndRotation = false;
  5972.  
  5973. this.rigidbody.AddForce(-muzzleFlashLight.up * (projForce * projKick), ForceMode.Impulse);
  5974.  
  5975. Destroy(burstTrailFX.gameObject, 1.25f);
  5976.  
  5977. if (gunType == 3) Destroy(bulletTwo.gameObject, 4f);
  5978. if (gunType == 2) Destroy(bulletTwo.gameObject, 4f);
  5979. if (gunType == 1) Destroy(bulletTwo.gameObject, 7f);
  5980. if (gunType == 0) Destroy(bulletTwo.gameObject, 95f);
  5981.  
  5982. this.muzzleFlashLightTwo.GetComponents<Light>().FirstOrDefault().enabled = false;
  5983.  
  5984. bulletThree = GameObject.CreatePrimitive(PrimitiveType.Cube);
  5985. bulletThree.SetActive(true);
  5986. bulletThree.renderer.enabled = false;
  5987.  
  5988. Transform placeItHereThree = (transform.Find("model/Turret/turretBody/turretElevator/spawnBulletThree"));
  5989. bulletThree.transform.position = placeItHereThree.position;
  5990. bulletThree.transform.rotation = placeItHereThree.rotation;
  5991.  
  5992. Rigidbody rbThree = bulletThree.AddComponent<Rigidbody>();
  5993. rbThree.collider.enabled = true;
  5994. rbThree.collider.isTrigger = true;
  5995. rbThree.useGravity = true;
  5996. rbThree.detectCollisions = true;
  5997. rbThree.collisionDetectionMode = CollisionDetectionMode.Continuous;
  5998. rbThree.mass = projMass;
  5999. rbThree.drag = projDrag;
  6000. rbThree.velocity = this.vessel.rigidbody.velocity;
  6001. rbThree.AddForce(rbThree.transform.up * projForce, ForceMode.Impulse);
  6002. impact imp3 = bullet.AddComponent<impact>();
  6003. imp3.useHardness = this.ordHardness;
  6004. imp3.useWarheadType = this.warheadType;
  6005. imp3.useProjPenetrate = this.projPenetrate;
  6006. imp3.bulletHoleChance = bulletFXChance;
  6007. imp3.bulletHoleTime = bulletFXLife;
  6008. imp3.wasDirected = hasActiveDirector;
  6009. burstTrailFX = (GameObject)GameObject.Instantiate(UnityEngine.Resources.Load("Effects/fx_exhaustFlame_yellow_tiny"));
  6010. burstTrailFX.particleEmitter.emit = true;
  6011. burstTrailFX.transform.parent = (bulletThree.transform);
  6012. burstTrailFX.transform.localPosition = new Vector3(0, 0, 0);
  6013. burstTrailFX.transform.rotation = bulletThree.transform.rotation;
  6014. burstTrailFX.particleEmitter.useWorldSpace = false;
  6015. burstTrailFX.particleEmitter.minSize = 0.3f;
  6016. burstTrailFX.particleEmitter.maxSize = 0.3f;
  6017. burstTrailFX.particleEmitter.localVelocity = new Vector3(0, 0, 0);
  6018. burstTrailFX.particleEmitter.minEnergy = 15f;
  6019. burstTrailFX.particleEmitter.maxEnergy = 15f;
  6020. burstTrailFX.particleEmitter.minEmission = 35f;
  6021. burstTrailFX.particleEmitter.maxEmission = 35f;
  6022. burstTrailFX.particleEmitter.angularVelocity = 0.01f;
  6023. burstTrailFX.particleEmitter.rndRotation = false;
  6024.  
  6025. this.rigidbody.AddForce(-muzzleFlashLight.up * (projForce * projKick), ForceMode.Impulse);
  6026.  
  6027. Destroy(burstTrailFX.gameObject, 1.25f);
  6028.  
  6029. if (gunType == 3) Destroy(bulletThree.gameObject, 4f);
  6030. if (gunType == 2) Destroy(bulletThree.gameObject, 4f);
  6031. if (gunType == 1) Destroy(bulletThree.gameObject, 7f);
  6032. if (gunType == 0) Destroy(bulletThree.gameObject, 95f);
  6033.  
  6034. this.muzzleFlashLightThree.GetComponents<Light>().FirstOrDefault().enabled = false;
  6035.  
  6036. }
  6037.  
  6038. }
  6039. #endregion
  6040.  
  6041. Rigidbody rb = bullet.AddComponent<Rigidbody>(); // ***********************
  6042. rb.collider.enabled = true;
  6043. rb.collider.isTrigger = true;
  6044. rb.useGravity = true;
  6045. rb.detectCollisions = true;
  6046. rb.collisionDetectionMode = CollisionDetectionMode.Continuous;
  6047. rb.mass = projMass;
  6048. rb.drag = projDrag;
  6049. rb.velocity = this.vessel.rigidbody.velocity;
  6050. rb.AddForce(rb.transform.up * projForce, ForceMode.Impulse);
  6051. impact imp = bullet.AddComponent<impact>();
  6052. imp.useHardness = this.ordHardness;
  6053. imp.useWarheadType = this.warheadType;
  6054. imp.useProjPenetrate = this.projPenetrate;
  6055. imp.bulletHoleChance = bulletFXChance;
  6056. imp.bulletHoleTime = bulletFXLife;
  6057. imp.wasDirected = hasActiveDirector;
  6058. burstTrailFX = (GameObject)GameObject.Instantiate(UnityEngine.Resources.Load("Effects/fx_exhaustFlame_yellow_tiny"));
  6059. burstTrailFX.particleEmitter.emit = true;
  6060. burstTrailFX.transform.parent = (bullet.transform);
  6061. burstTrailFX.transform.localPosition = new Vector3(0, 0, 0);
  6062. burstTrailFX.transform.rotation = bullet.transform.rotation;
  6063. burstTrailFX.particleEmitter.useWorldSpace = false;
  6064. burstTrailFX.particleEmitter.minSize = 0.3f;
  6065. burstTrailFX.particleEmitter.maxSize = 0.3f;
  6066. burstTrailFX.particleEmitter.localVelocity = new Vector3(0, 0, 0);
  6067. burstTrailFX.particleEmitter.minEnergy = 15f;
  6068. burstTrailFX.particleEmitter.maxEnergy = 15f;
  6069. burstTrailFX.particleEmitter.minEmission = 35f;
  6070. burstTrailFX.particleEmitter.maxEmission = 35f;
  6071. burstTrailFX.particleEmitter.angularVelocity = 0.01f;
  6072. burstTrailFX.particleEmitter.rndRotation = false;
  6073.  
  6074. Destroy(burstTrailFX.gameObject, 1.25f);
  6075.  
  6076.  
  6077. this.rigidbody.AddForce(-muzzleFlashLight.forward * (projForce * projKick), ForceMode.Impulse);
  6078.  
  6079.  
  6080. fireBurst = false;
  6081. bulletCoolTimer = rateOfFire + UnityEngine.Random.value;
  6082.  
  6083. if(gunType == 3) Destroy(bullet.gameObject, 4f);
  6084. if (gunType == 2) Destroy(bullet.gameObject, 4f);
  6085. if (gunType == 1) Destroy(bullet.gameObject, 7f);
  6086. if (gunType == 0) Destroy(bullet.gameObject, 95f);
  6087.  
  6088. fireCannonFX.particleEmitter.emit = false;
  6089. this.muzzleFlashLight.GetComponents<Light>().FirstOrDefault().enabled = false;
  6090.  
  6091. return;
  6092.  
  6093. }
  6094.  
  6095. public void checkGunDirector()
  6096. {
  6097. foreach (Part aPart in this.vessel.Parts)
  6098. {
  6099. try
  6100. {
  6101. thisGunDirector = aPart.GetComponentInChildren<gunDirector>();
  6102. }
  6103. catch
  6104. {
  6105. Debug.Log("problem finding gunDirector on this part/vessel!");
  6106. }
  6107.  
  6108. if (thisGunDirector != null)
  6109. {
  6110. if (thisGunDirector.inAction == true)
  6111. {
  6112. hasActiveDirector = true;
  6113.  
  6114. shotPrediction = AnimationCurve.Linear(246f, -3f, 8514f, 12f);
  6115. shotPrediction.AddKey(312f, -2f);
  6116. shotPrediction.AddKey(535f, -1f);
  6117. shotPrediction.AddKey(1252f, 0f);
  6118. shotPrediction.AddKey(2887f, 1f);
  6119. shotPrediction.AddKey(4483f, 2f);
  6120. shotPrediction.AddKey(5598f, 3f);
  6121. shotPrediction.AddKey(6357f, 4f);
  6122. shotPrediction.AddKey(7044f, 5f);
  6123. shotPrediction.AddKey(7826f, 7f);
  6124. shotPrediction.AddKey(8382f, 10f);
  6125. shotPrediction.AddKey(8477f, 11f);
  6126.  
  6127. if (FlightGlobals.fetch.vesselTargetMode != FlightGlobals.VesselTargetModes.None)
  6128. {
  6129. ITargetable target = FlightGlobals.fetch.VesselTarget;
  6130. Vessel targetedVessel = target.GetVessel();
  6131. targetDistance = Vector3.Distance(this.vessel.transform.position, targetedVessel.transform.position);
  6132.  
  6133. if (targetDistance <= 8514f && targetDistance >= 246f)
  6134. {
  6135. ScreenMessages.PostScreenMessage(new ScreenMessage("Use " + shotPrediction.Evaluate(targetDistance) + " Degrees Elevation", 4f, ScreenMessageStyle.UPPER_CENTER));
  6136. }
  6137. else
  6138. {
  6139. ScreenMessages.PostScreenMessage(new ScreenMessage("Cannot Calculate Solution, Out Of Min/Max Range!", 4f, ScreenMessageStyle.UPPER_CENTER));
  6140. }
  6141. }
  6142.  
  6143. }
  6144. else hasActiveDirector = false;
  6145.  
  6146. }
  6147.  
  6148. }
  6149. }
  6150.  
  6151. public void getClosestHostile()
  6152. {
  6153. hostileOne = null;
  6154. hostileTwo = null;
  6155. hostileThree = null;
  6156. targetHostile = null;
  6157.  
  6158. List<Vessel> calledList = IFFList.Instance.IFFRed();
  6159. if (calledList.Contains(this.vessel))
  6160. {
  6161. List<Vessel> lookForBlueTarget = IFFList.Instance.IFFBlue();
  6162.  
  6163. if (lookForBlueTarget.Count > 0)
  6164. {
  6165. foreach (Vessel bVessel in lookForBlueTarget)
  6166. {
  6167. float bTargetDistance = Vector3.Distance(this.vessel.transform.position, bVessel.transform.position);
  6168.  
  6169. if (bTargetDistance <= 3000f && bTargetDistance > 2000f)
  6170. {
  6171. hostileThree = bVessel;
  6172. }
  6173. if (bTargetDistance <= 2000 && bTargetDistance > 1500f)
  6174. {
  6175. hostileTwo = bVessel;
  6176. }
  6177. if (bTargetDistance <= 1500f)
  6178. {
  6179. hostileOne = bVessel;
  6180. }
  6181.  
  6182. foreach (Part p in bVessel.Parts)
  6183. {
  6184. #region antimissile search
  6185. if (p.partName.Contains("PartMissile") && this.isCIWS == true)
  6186. {
  6187. if (p.rigidbody.velocity.magnitude > 200f)
  6188. {
  6189. Vector3 headingDirection = (p.rigidbody.transform.position - turretTransform.position);
  6190. Vector3 forward;
  6191. forward = p.transform.forward;
  6192. if (Vector3.Dot(forward, headingDirection.normalized) > 0f)
  6193. {
  6194. //print("Moving Away");
  6195. }
  6196. else
  6197. {
  6198. hostileClosing = true;
  6199. }
  6200.  
  6201. if (hostileClosing == true)
  6202. {
  6203. float chanceToIntercept = 0.75f;
  6204. float numberRolled = UnityEngine.Random.value * 100f;
  6205.  
  6206. if (chanceToIntercept > numberRolled)
  6207. {
  6208. //print("Intercept roll was " + numberRolled);
  6209. p.explode();
  6210. print("Romfarer missile destroyed by CIWS!");
  6211.  
  6212. }
  6213. }
  6214. }
  6215.  
  6216.  
  6217. }
  6218. #endregion
  6219. }
  6220. }
  6221. }
  6222.  
  6223.  
  6224. if (hostileOne != null)
  6225. {
  6226. targetHostile = hostileOne;
  6227. }
  6228. else if (hostileTwo != null)
  6229. {
  6230. targetHostile = hostileTwo;
  6231. }
  6232. else if (hostileThree != null)
  6233. {
  6234. targetHostile = hostileThree;
  6235. }
  6236.  
  6237. if (hostileOne == null && hostileTwo == null && hostileThree == null)
  6238. {
  6239. targetHostile = null;
  6240. }
  6241.  
  6242. }
  6243. else
  6244. {
  6245. List<Vessel> calledNextList = IFFList.Instance.IFFBlue();
  6246. if (calledNextList.Contains(this.vessel))
  6247. {
  6248. List<Vessel> lookForRedTarget = IFFList.Instance.IFFRed();
  6249.  
  6250.  
  6251. if (lookForRedTarget.Count > 0)
  6252. {
  6253. foreach (Vessel bVessel in lookForRedTarget)
  6254. {
  6255. float bTargetDistance = Vector3.Distance(this.vessel.transform.position, bVessel.transform.position);
  6256.  
  6257. if (bTargetDistance <= 3000f && bTargetDistance > 2000f)
  6258. {
  6259. hostileThree = bVessel;
  6260. }
  6261. if (bTargetDistance <= 2000 && bTargetDistance > 1500f)
  6262. {
  6263. hostileTwo = bVessel;
  6264. }
  6265. if (bTargetDistance <= 1500f)
  6266. {
  6267. hostileOne = bVessel;
  6268. }
  6269.  
  6270. foreach (Part p in bVessel.Parts)
  6271. {
  6272. #region antimissile search
  6273. if (p.partName.Contains("PartMissile"))
  6274. {
  6275. if (p.rigidbody.velocity.magnitude > 200f)
  6276. {
  6277.  
  6278. Vector3 headingDirection = (p.rigidbody.transform.position - turretTransform.position);
  6279. Vector3 forward;
  6280. forward = p.transform.forward;
  6281. if (Vector3.Dot(forward, headingDirection.normalized) > 0f)
  6282. {
  6283. //print("Moving Away");
  6284.  
  6285. }
  6286. else
  6287. {
  6288.  
  6289. hostileClosing = true;
  6290. }
  6291.  
  6292. if (hostileClosing == true)
  6293. {
  6294. float chanceToIntercept = 0.75f;
  6295. float numberRolled = UnityEngine.Random.value * 100f;
  6296.  
  6297. if (chanceToIntercept > numberRolled)
  6298. {
  6299. //print("Intercept roll was " + numberRolled);
  6300. p.explode();
  6301. print("Romfarer missile destroyed by CIWS!");
  6302.  
  6303. }
  6304. }
  6305. }
  6306.  
  6307.  
  6308. }
  6309. #endregion
  6310. }
  6311. }
  6312. }
  6313.  
  6314. if (hostileOne != null)
  6315. {
  6316. targetHostile = hostileOne;
  6317. }
  6318. else if (hostileTwo != null)
  6319. {
  6320. targetHostile = hostileTwo;
  6321. }
  6322. else if (hostileThree != null)
  6323. {
  6324. targetHostile = hostileThree;
  6325. }
  6326.  
  6327. if (hostileOne == null && hostileTwo == null && hostileThree == null)
  6328. {
  6329. targetHostile = null;
  6330. }
  6331.  
  6332. }
  6333. }
  6334.  
  6335.  
  6336. }
  6337.  
  6338. public void autoTracker()
  6339. {
  6340. #region Ball Turret Tracking
  6341. if (turretType == 0 && isTurret == true)
  6342. {
  6343. if (FlightGlobals.fetch.vesselTargetMode != FlightGlobals.VesselTargetModes.None && autoTrackOn == true && guardMode == false)
  6344. {
  6345. float rotSpdMod = checkElectricity.useElectricCharge(base.part, 0.025);
  6346. if (this.vessel == FlightGlobals.ActiveVessel && rotSpdMod > 0.5f)
  6347. {
  6348. float shotGrouping = 0.15f;
  6349. ITargetable target = FlightGlobals.fetch.VesselTarget;
  6350. Vessel v = FlightGlobals.fetch.VesselTarget.GetVessel();
  6351. var lookPos = (target.GetTransform().position - turretTransform.position).normalized;
  6352. var rotation = Quaternion.LookRotation(lookPos, transform.up);
  6353. rotation.x += ((UnityEngine.Random.value - 0.5f) / 100) * shotGrouping;
  6354. rotation.y += ((UnityEngine.Random.value - 0.5f) / 100) * shotGrouping;
  6355. rotation.z += ((UnityEngine.Random.value - 0.5f) / 100) * shotGrouping;
  6356.  
  6357.  
  6358. turretTransform.rotation = Quaternion.Slerp(turretTransform.rotation, rotation, 1f);
  6359.  
  6360. currentTurretLocation = turretTransform.position;
  6361. currentTurretAngle = lookPos;
  6362.  
  6363. if (smartTracking == true)
  6364. {
  6365. foreach (Part p in v.parts)
  6366. {
  6367.  
  6368. foreach (PartModule aModule in p.Modules)
  6369. {
  6370.  
  6371. if (aModule is relayIFF)
  6372. {
  6373. relayIFF checkTargetIFF = aModule.GetComponent<relayIFF>();
  6374.  
  6375. if (p.vessel != base.vessel && checkTargetIFF.setIFF != this.setIFF)
  6376. {
  6377. shotGrouping = 0.25f;
  6378.  
  6379. float leadAmount = 0.4f;
  6380.  
  6381. leadTarget.SetActive(true);
  6382. leadTarget.renderer.enabled = false;
  6383. leadTarget.collider.enabled = false;
  6384. Transform placeLeadTarget = p.vessel.transform;
  6385. leadTarget.transform.rotation = placeLeadTarget.transform.rotation;
  6386. Vector3 changeVector = this.vessel.rigidbody.velocity;
  6387. Vector3 changeVectorNormalized = Vector3.Normalize(changeVector);
  6388. float magnitude = Vector3.Magnitude(changeVector);
  6389.  
  6390. leadTarget.transform.position = p.vessel.transform.position - (changeVectorNormalized * (magnitude * leadAmount));
  6391.  
  6392. lookPos = (leadTarget.transform.position - turretTransform.position).normalized;
  6393. rotation = Quaternion.LookRotation(lookPos, transform.up);
  6394.  
  6395.  
  6396. rotation.x += ((UnityEngine.Random.value - 0.5f) / 40f) * shotGrouping;
  6397. rotation.y += ((UnityEngine.Random.value - 0.5f) / 40f) * shotGrouping;
  6398. rotation.z += ((UnityEngine.Random.value - 0.5f) / 40f) * shotGrouping;
  6399.  
  6400.  
  6401. turretTransform.rotation = rotation;
  6402.  
  6403. currentTurretLocation = turretTransform.position;
  6404. currentTurretAngle = lookPos;
  6405.  
  6406.  
  6407.  
  6408. }
  6409. }
  6410.  
  6411. }
  6412. }
  6413.  
  6414.  
  6415.  
  6416. }
  6417.  
  6418.  
  6419. }
  6420.  
  6421.  
  6422.  
  6423. }
  6424.  
  6425.  
  6426. if (this.vessel != FlightGlobals.ActiveVessel && autoTrackOn == true && guardMode == true) //***********************
  6427. {
  6428. Vector3 BoatPosition = this.vessel.transform.position;
  6429.  
  6430. getClosestHostile();
  6431. float rotSpdMod = checkElectricity.useElectricCharge(base.part, 0.025);
  6432. if (targetHostile != null && rotSpdMod > 0.5f)
  6433. {
  6434. float shotGrouping = 0.2f;
  6435.  
  6436. float leadAmount = guiLead;
  6437.  
  6438. leadMulti = 1f;
  6439.  
  6440. if (Vector3.Distance(BoatPosition, targetHostile.transform.position) > 550f)
  6441. {
  6442. leadMulti = (Vector3.Distance(BoatPosition, targetHostile.transform.position) - 550f) / 625f;
  6443. if (leadMulti > 0f) leadMulti += 1f;
  6444.  
  6445. }
  6446.  
  6447. leadAmount = guiLead * leadMulti;
  6448.  
  6449. float leadSpdSteps = ((targetHostile.rigidbody.velocity.magnitude - 100f) / 100f) * 0.1f;
  6450.  
  6451. leadAmount += leadSpdSteps;
  6452.  
  6453. leadTarget.SetActive(true);
  6454. leadTarget.renderer.enabled = false; //true to debug
  6455. leadTarget.collider.enabled = false;
  6456. Transform placeLeadTarget = targetHostile.transform;
  6457. leadTarget.transform.rotation = placeLeadTarget.transform.rotation;
  6458. Vector3 changeVector = targetHostile.rigidbody.velocity;
  6459. Vector3 changeVectorNormalized = Vector3.Normalize(changeVector);
  6460. float magnitude = Vector3.Magnitude(changeVector);
  6461.  
  6462. leadTarget.transform.position = targetHostile.transform.position + (changeVectorNormalized * (magnitude * leadAmount));
  6463.  
  6464. var lookPos = (leadTarget.transform.position - turretTransform.position).normalized;
  6465. var rotation = Quaternion.LookRotation(lookPos, transform.up);
  6466.  
  6467. if (targetHostile.rigidbody.velocity.magnitude > 400d)
  6468. {
  6469. rotation.x += (((float)rndNumber.rndDouble(0.0, 1.0) - 0.5f) / 120f) * shotGrouping;
  6470. rotation.y += (((float)rndNumber.rndDouble(0.0, 1.0) - 0.5f) / 120f) * shotGrouping;
  6471. rotation.z += (((float)rndNumber.rndDouble(0.0, 1.0) - 0.5f) / 120f) * shotGrouping;
  6472. rateOfFire = origRateOfFire;
  6473. }
  6474. if (targetHostile.rigidbody.velocity.magnitude > 150d && targetHostile.rigidbody.velocity.magnitude <= 400d)
  6475. {
  6476. rotation.x += (((float)rndNumber.rndDouble(0.0, 1.0) - 0.5f) / 250f) * shotGrouping;
  6477. rotation.y += (((float)rndNumber.rndDouble(0.0, 1.0) - 0.5f) / 250f) * shotGrouping;
  6478. rotation.z += (((float)rndNumber.rndDouble(0.0, 1.0) - 0.5f) / 250f) * shotGrouping;
  6479. rateOfFire = origRateOfFire * 1.035f;
  6480.  
  6481. }
  6482. if (targetHostile.rigidbody.velocity.magnitude > 100d && targetHostile.rigidbody.velocity.magnitude <= 150d)
  6483. {
  6484. rotation.x += (((float)rndNumber.rndDouble(0.0, 1.0) - 0.5f) / 300f) * shotGrouping;
  6485. rotation.y += (((float)rndNumber.rndDouble(0.0, 1.0) - 0.5f) / 300f) * shotGrouping;
  6486. rotation.z += (((float)rndNumber.rndDouble(0.0, 1.0) - 0.5f) / 300f) * shotGrouping;
  6487. rateOfFire = origRateOfFire * 1.0875f;
  6488. }
  6489. if (targetHostile.rigidbody.velocity.magnitude > 50d && targetHostile.rigidbody.velocity.magnitude <= 100d)
  6490. {
  6491. rotation.x += (((float)rndNumber.rndDouble(0.0, 1.0) - 0.5f) / 450f) * shotGrouping;
  6492. rotation.y += (((float)rndNumber.rndDouble(0.0, 1.0) - 0.5f) / 450f) * shotGrouping;
  6493. rotation.z += (((float)rndNumber.rndDouble(0.0, 1.0) - 0.5f) / 450f) * shotGrouping;
  6494. rateOfFire = origRateOfFire * 1.25f;
  6495. }
  6496. if (targetHostile.rigidbody.velocity.magnitude > 0d && targetHostile.rigidbody.velocity.magnitude <= 50d)
  6497. {
  6498.  
  6499.  
  6500. rateOfFire = origRateOfFire * 2.5f;
  6501. }
  6502. turretTransform.rotation = rotation;
  6503.  
  6504. currentTurretLocation = turretTransform.position;
  6505. currentTurretAngle = lookPos;
  6506.  
  6507. safetyLOS();
  6508.  
  6509. if (randomBurstTimer > 0f)
  6510. {
  6511. randomBurstTimer--;
  6512.  
  6513. fireCannonBurst();
  6514. }
  6515. if (randomBurstTimer <= 0f)
  6516. {
  6517. float randBurstChance = (float)rndNumber.rndRoll(5, 10);
  6518. float rollToBurst = (float)rndNumber.rndRoll(0, 100);
  6519.  
  6520. if (this.isCIWS == true) rollToBurst = 1f;
  6521.  
  6522. if (rollToBurst < randBurstChance)
  6523. {
  6524. randomBurstTimer = (float)rndNumber.rndDouble(60.0, 120.0);
  6525. }
  6526.  
  6527. if (this.isCIWS == true) randomBurstTimer = 1f;
  6528. }
  6529. }
  6530. }
  6531. }
  6532. #endregion
  6533.  
  6534. #region Dual Zone Turret manual control
  6535. if (turretType == 1)
  6536. {
  6537. if (autoTrackOn == false && guardMode == false)
  6538. {
  6539. if (this.vessel == FlightGlobals.ActiveVessel && ctrlTurret == true)
  6540. {
  6541.  
  6542.  
  6543. if (Input.GetKey(KeyCode.Keypad0))
  6544. {
  6545. float rotSpdMod = checkElectricity.useElectricCharge(base.part, 0.045);
  6546. float rotSpeed = 0f;
  6547. if (invertRotation == true)
  6548. {
  6549. rotSpeed = ((14f / this.part.mass) * turretSpeed) * rotSpdMod;
  6550. }
  6551. else if (invertRotation == false)
  6552. {
  6553. rotSpeed = ((-14f / this.part.mass) * turretSpeed) * rotSpdMod;
  6554. }
  6555.  
  6556. turretBodyRotate.transform.Rotate(Vector3.forward * rotSpeed * Time.deltaTime);
  6557. }
  6558. if (Input.GetKey(KeyCode.KeypadPeriod))
  6559. {
  6560. float rotSpdMod = checkElectricity.useElectricCharge(base.part, 0.045);
  6561. float rotSpeed = 0f;
  6562. if (invertRotation == true)
  6563. {
  6564. rotSpeed = ((-14f / this.part.mass) * turretSpeed) * rotSpdMod;
  6565. }
  6566. else if (invertRotation == false)
  6567. {
  6568. rotSpeed = ((14f / this.part.mass) * turretSpeed) * rotSpdMod;
  6569. }
  6570. turretBodyRotate.transform.Rotate(Vector3.forward * rotSpeed * Time.deltaTime);
  6571. }
  6572. if (Input.GetKey(KeyCode.Keypad5))
  6573. {
  6574. float changeRate;
  6575. float rotSpdMod = checkElectricity.useElectricCharge(base.part, 0.035);
  6576. changeRate = (((-1.75f / (this.part.mass * 0.25f)) * turretSpeed) * rotSpdMod) *Time.deltaTime;
  6577. showTurretElevation -= changeRate;
  6578. turretBarrelElevation.transform.Rotate(0f, 0f, changeRate);
  6579.  
  6580. }
  6581. if (Input.GetKey(KeyCode.Keypad2))
  6582. {
  6583. float changeRate;
  6584. float rotSpdMod = checkElectricity.useElectricCharge(base.part, 0.035);
  6585. changeRate = (((1.75f / (this.part.mass * 0.25f)) * turretSpeed) * rotSpdMod) * Time.deltaTime;
  6586. showTurretElevation -= changeRate;
  6587. turretBarrelElevation.transform.Rotate(0f, 0f, changeRate);
  6588.  
  6589. }
  6590.  
  6591.  
  6592. }
  6593. }
  6594. }
  6595. #endregion
  6596.  
  6597.  
  6598. }
  6599.  
  6600.  
  6601.  
  6602. public void safetyLOS()
  6603. {
  6604. float range = 3000f;
  6605. Vessel vesselHit;
  6606. vesselHit = null;
  6607. fireOverride = false;
  6608. tripOverride = false;
  6609.  
  6610.  
  6611. rayLOS = new Ray(currentTurretLocation, currentTurretAngle);
  6612. if (Physics.Raycast(rayLOS.origin, rayLOS.direction, out hitLOS, range))
  6613. {
  6614.  
  6615. if (hitLOS.collider.attachedRigidbody != null)
  6616. {
  6617.  
  6618. Part hitPart = hitLOS.collider.attachedRigidbody.GetComponent<Part>();
  6619. if (hitPart != null)
  6620. {
  6621.  
  6622. vesselHit = hitPart.vessel;
  6623.  
  6624. if (vesselHit != null)
  6625. {
  6626. List<Vessel> calledList = IFFList.Instance.IFFBlue();
  6627. List<Vessel> calledNextList = IFFList.Instance.IFFRed();
  6628. if (calledList.Contains(this.vessel) && calledList.Contains(vesselHit) || calledNextList.Contains(this.vessel) && calledNextList.Contains(vesselHit) || this.vessel == vesselHit)
  6629. {
  6630. tripOverride = true;
  6631. }
  6632.  
  6633. }
  6634.  
  6635. }
  6636.  
  6637. }
  6638.  
  6639.  
  6640. if (hitLOS.collider.gameObject.layer == 15) fireOverride = true;
  6641. if (tripOverride == true)
  6642. {
  6643. fireOverride = true;
  6644.  
  6645. }
  6646. }
  6647.  
  6648.  
  6649. }
  6650.  
  6651. }
  6652.  
  6653. public class impact : MonoBehaviour
  6654. {
  6655.  
  6656. public float collisionForce;
  6657.  
  6658. public float useHardness;
  6659.  
  6660. public float useWarheadType;
  6661.  
  6662. public float useProjPenetrate;
  6663.  
  6664. public bool doItOnce = true;
  6665.  
  6666. public float skinWidth = 0.05f;
  6667.  
  6668. private float minimumExtent;
  6669. private float partialExtent;
  6670. private float sqrMinimumExtent;
  6671. private float lastGoodVelocity;
  6672.  
  6673. public bool wasDirected = false;
  6674.  
  6675. public Rigidbody rb;
  6676.  
  6677. public GameObject bulletHoleInstance;
  6678.  
  6679. public float bulletHoleChance;
  6680. public float bulletHoleTime;
  6681.  
  6682. public bool spawnOneFX = true;
  6683.  
  6684. public Vector3 previousPosition;
  6685.  
  6686. public Vector3 thisWayUp;
  6687.  
  6688. public RaycastHit sendLastGoodRaycastHit;
  6689.  
  6690. public float origDrag;
  6691. public double partAltitude;
  6692.  
  6693.  
  6694. void Awake()
  6695. {
  6696. rb = this.rigidbody;
  6697. previousPosition = rb.position;
  6698. minimumExtent = Mathf.Min(Mathf.Min(collider.bounds.extents.x, collider.bounds.extents.y), collider.bounds.extents.z);
  6699. partialExtent = minimumExtent * (1.0f - skinWidth);
  6700. sqrMinimumExtent = minimumExtent * minimumExtent;
  6701.  
  6702. }
  6703.  
  6704.  
  6705. public void FixedUpdate()
  6706. {
  6707. thisWayUp = (this.transform.position - FlightGlobals.ActiveVessel.mainBody.position).normalized;
  6708.  
  6709. if (this.gameObject != null)
  6710. {
  6711. partAltitude = Vector3.Distance(this.rigidbody.transform.position, FlightGlobals.ActiveVessel.mainBody.position) - (float)FlightGlobals.ActiveVessel.mainBody.Radius;
  6712.  
  6713. Vector3 movementThisStep = rb.position - previousPosition;
  6714. float movementSqrMagnitude = movementThisStep.sqrMagnitude;
  6715.  
  6716. if (movementSqrMagnitude > sqrMinimumExtent)
  6717. {
  6718. float movementMagnitude = Mathf.Sqrt(movementSqrMagnitude);
  6719. RaycastHit hitInfo;
  6720.  
  6721.  
  6722. #region bullet hole trial code
  6723. //print(hitInfo.collider.gameObject.layer);
  6724.  
  6725.  
  6726.  
  6727. //if (spawnOneFX == true) //only make one fx
  6728. //{
  6729.  
  6730. // if (hitInfo.collider.gameObject.layer != 15)
  6731.  
  6732. // {
  6733. // #region Place a bullet hole gameobject where the raycast hit.
  6734. // try
  6735. // {
  6736. // bulletHoleInstance = GameDatabase.Instance.GetModel("IDSkillfulR1/Parts/bulletDecal/model");
  6737.  
  6738. // }
  6739. // catch
  6740. // {
  6741. // Debug.Log("Problem finding bullet hole decal!");
  6742. // }
  6743.  
  6744. // if (bulletHoleInstance != null)
  6745. // {
  6746. // //print("Inside spawning bullet hole!");
  6747. // float bulletHoleScale = (float)Math.Sqrt(rb.mass) * 3f;
  6748. // //print("step1");
  6749. // GameObject newBulletHit = (GameObject)GameObject.Instantiate(bulletHoleInstance, hitInfo.point + (hitInfo.normal * 0.001f * (float)rndNumber.rndDouble(0.01, 0.001)), Quaternion.LookRotation(-hitInfo.normal));
  6750. // //print("step2");
  6751. // newBulletHit.transform.parent = hitInfo.collider.transform;
  6752. // //print("step3");
  6753. // newBulletHit.transform.localScale = new Vector3(bulletHoleScale, bulletHoleScale, 0.00001f);
  6754. // //print("step4");
  6755. // newBulletHit.SetActive(true);
  6756. // //print("step5");
  6757. // GameObject.Destroy(newBulletHit, bulletHoleTime); //set bulletFXLife in gun cfg to affect this bulletHoleTime - default is 10 seconds
  6758. // spawnOneFX = false;
  6759. // }
  6760.  
  6761. // #endregion
  6762.  
  6763. // Destroy(this.gameObject, 0.5f);
  6764. // }
  6765. //}
  6766. #endregion
  6767. if (Physics.Raycast(previousPosition, movementThisStep, out hitInfo, movementMagnitude, 1))
  6768. {
  6769. rb.position = hitInfo.point - (movementThisStep / movementMagnitude) * partialExtent;
  6770.  
  6771. }
  6772.  
  6773. }
  6774.  
  6775. if (this.partAltitude < -3.0)
  6776. {
  6777. //print("Projectile Hit the water!");
  6778. if (wasDirected == true)
  6779. {
  6780. ScreenMessages.PostScreenMessage(new ScreenMessage("Water impact at range: " + Vector3.Distance(rb.transform.position, FlightGlobals.ActiveVessel.transform.position), 4f, ScreenMessageStyle.UPPER_CENTER));
  6781. //print("Water impact at range: " + Vector3.Distance(rb.transform.position, FlightGlobals.ActiveVessel.transform.position));
  6782. }
  6783.  
  6784. if (rb.mass >= 0.01f)
  6785. {
  6786.  
  6787. GameObject fxSplashInstance = new GameObject();
  6788.  
  6789. try
  6790. {
  6791.  
  6792. fxSplashInstance = GameDatabase.Instance.GetModel("IDSkillfulR1/Effects/largeSplash/model");
  6793. }
  6794. catch
  6795. {
  6796. print("Problem locating largeSplash");
  6797. }
  6798.  
  6799. if (fxSplashInstance != null)
  6800. {
  6801.  
  6802. fxSplashInstance.transform.position = this.transform.position;
  6803. fxSplashInstance.transform.LookAt(FlightGlobals.ActiveVessel.mainBody.transform);
  6804.  
  6805. fxSplashInstance.SetActive(true);
  6806.  
  6807. endFx fxSplashEnds = fxSplashInstance.AddComponent<endFx>();
  6808. fxSplashEnds.endTime = 2f;
  6809.  
  6810. Destroy(fxSplashInstance, 8f * rb.mass);
  6811. }
  6812.  
  6813.  
  6814. }
  6815.  
  6816. FXMonger.Splash(this.transform.position, (this.rigidbody.velocity.magnitude * (this.rigidbody.mass * 100f)));
  6817.  
  6818. Destroy(this.gameObject);
  6819. }
  6820.  
  6821. if (rb.velocity.magnitude < 50f)
  6822. {
  6823. Destroy(this.gameObject, 0.0f);
  6824. }
  6825.  
  6826. previousPosition = rb.position;
  6827.  
  6828. lastGoodVelocity = rb.velocity.magnitude;
  6829. }
  6830.  
  6831.  
  6832. }
  6833.  
  6834. public void OnTriggerEnter(Collider Collision)
  6835. {
  6836. if (Collision.gameObject.layer == 15)
  6837. {
  6838. if (wasDirected == true)
  6839. {
  6840. ScreenMessages.PostScreenMessage(new ScreenMessage("Shot impacted ground/structure at range: " + Vector3.Distance(rb.transform.position, FlightGlobals.ActiveVessel.transform.position), 4f, ScreenMessageStyle.UPPER_CENTER));
  6841. //print("Shot impacted ground/structure at range: " + Vector3.Distance(rb.transform.position, FlightGlobals.ActiveVessel.transform.position));
  6842. }
  6843. if (useWarheadType == 1f || useWarheadType == 2f) FXMonger.Explode(FlightGlobals.ActiveVessel.rootPart, this.transform.position, rb.mass);
  6844. terrainHit();
  6845.  
  6846. }
  6847. }
  6848.  
  6849. public static void doShrapnel(GameObject thisProjectile, float projMass, Vector3 projSpeed, float explodePower)
  6850. {
  6851. int shrapLimit = 2;
  6852. #region Shrapnel Limit
  6853. if (projMass < 0.25f)
  6854. {
  6855. shrapLimit = 4;
  6856. }
  6857. if (projMass >= 0.25f && projMass < 0.5f)
  6858. {
  6859. shrapLimit = rndNumber.rndRoll(4, 8);
  6860. }
  6861. if (projMass >= 0.5f && projMass < 1f)
  6862. {
  6863. shrapLimit = rndNumber.rndRoll(5, 16);
  6864. }
  6865. if (projMass >= 1f && projMass < 4f)
  6866. {
  6867. shrapLimit = rndNumber.rndRoll(6, 24);
  6868. }
  6869. if (projMass >= 4f && projMass < 10f)
  6870. {
  6871. shrapLimit = rndNumber.rndRoll(7, 32);
  6872. }
  6873. #endregion
  6874. int shrapnel = rndNumber.rndRoll(1, shrapLimit);
  6875.  
  6876. int fragCache = shrapnel;
  6877. GameObject[] exFrag = new GameObject[fragCache];
  6878. for (int i = 0; i < exFrag.Length; i++)
  6879. {
  6880. exFrag[i] = GameObject.CreatePrimitive(PrimitiveType.Cube);
  6881. exFrag[i].SetActive(true);
  6882. exFrag[i].renderer.enabled = false;
  6883. exFrag[i].transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);
  6884. exFrag[i].transform.position = thisProjectile.transform.position + UnityEngine.Random.insideUnitSphere * (explodePower * 0.225f);
  6885.  
  6886. Vector3 randomDirection = new Vector3(rndNumber.rndRoll(-359, 359), rndNumber.rndRoll(-359, 359), rndNumber.rndRoll(-359, 359));
  6887. exFrag[i].transform.Rotate(randomDirection);
  6888.  
  6889. Rigidbody rb = exFrag[i].AddComponent<Rigidbody>();
  6890. rb.detectCollisions = true;
  6891. rb.collisionDetectionMode = CollisionDetectionMode.Continuous;
  6892. rb.mass = (projMass / shrapnel);
  6893. rb.drag = rndNumber.rndFloat(0.1f, 0.3f);
  6894. rb.velocity = projSpeed * 0.75f;
  6895.  
  6896. setColliderStateInChildren(exFrag[i], true);
  6897.  
  6898. fragImpact fI = exFrag[i].AddComponent<fragImpact>();
  6899. fI.fragWarheadType = 0f;
  6900. fI.fragHardness = 320f;
  6901.  
  6902. Destroy(exFrag[i].gameObject, 5f);
  6903.  
  6904. }
  6905. }
  6906.  
  6907. public static void setColliderStateInChildren(GameObject rootObject, bool isTrigger)
  6908. {
  6909.  
  6910. Collider[] colliders = rootObject.GetComponentsInChildren<Collider>(true);
  6911. for (int i = 0; i < colliders.Length; i++)
  6912. {
  6913. colliders[i].isTrigger = isTrigger;
  6914. colliders[i].enabled = true;
  6915. }
  6916. }
  6917.  
  6918. public void terrainHit()
  6919. {
  6920.  
  6921.  
  6922. GameObject explosion = Part.Instantiate(UnityEngine.Resources.Load("Effects/fx_exhaustSparks_yellow")) as GameObject;
  6923. explosion.transform.localEulerAngles = Vector3.zero;
  6924. explosion.transform.localPosition = new Vector3(0, 0, 0);
  6925. explosion.transform.position = this.transform.position;
  6926. ParticleEmitter emitter = explosion.particleEmitter;
  6927. emitter.emit = false;
  6928. emitter.minSize = (rb.mass * 0.5f) + 0.35f;
  6929. emitter.maxSize = (rb.mass * 2f) + 1f;
  6930. emitter.minEnergy = (rb.mass * (rb.velocity.magnitude * 0.0025f)) + 1.2f;
  6931. emitter.maxEnergy = (rb.mass * (rb.velocity.magnitude *0.005f)) + 1.5f;
  6932. emitter.rndVelocity = Vector3.one * (float)rndNumber.rndDouble(0.01, 1.0);
  6933. emitter.localVelocity = Vector3.zero;
  6934. emitter.useWorldSpace = true;
  6935. ParticleAnimator emitterAnimator = emitter.GetComponent<ParticleAnimator>();
  6936. emitterAnimator.sizeGrow = 0.0035f;
  6937. Color[] emitterColors = emitterAnimator.colorAnimation;
  6938. emitterColors[0] = new Color(0.5f, 0.45f, 0.18f, 0.95f);
  6939. emitterColors[1] = new Color(0.8f, 0.8f, 0.8f, 1f);
  6940. emitterColors[2] = new Color(0.85f, 0.1f, 0.1f, 0.7f);
  6941. emitterColors[3] = new Color(0.5f, 0.5f, 0.5f, 0.5f);
  6942. emitterColors[4] = new Color(0f, 0f, 0f, 0.25f);
  6943. emitterAnimator.colorAnimation = emitterColors;
  6944.  
  6945. emitter.Emit(8);
  6946.  
  6947. if (useWarheadType == 1f && rb.mass >= 0.01f)
  6948. {
  6949. float explosionPower = rigidbody.mass * 500f;
  6950. float blastRadius = explosionPower * 0.25f;
  6951.  
  6952. foreach (Vessel v in FlightGlobals.Vessels)
  6953. {
  6954. float blastDistance = Vector3.Distance(v.transform.position, this.transform.position);
  6955. if (blastDistance < blastRadius)
  6956. {
  6957. try
  6958. {
  6959. v.GoOffRails();
  6960. }
  6961. catch
  6962. {
  6963. print("Something is wrong with making the vessel offrails");
  6964. }
  6965.  
  6966. FXMonger.Explode(v.rootPart, v.transform.position, 0.9f / blastDistance);
  6967. v.rigidbody.AddForceAtPosition(Vector3.forward * (explosionPower / (blastDistance * 0.25f)), v.transform.position, ForceMode.Impulse);
  6968.  
  6969. doShrapnel(this.gameObject, rb.mass, rb.velocity, explosionPower);
  6970. }
  6971. }
  6972.  
  6973. }
  6974. if (useWarheadType == 2f && rb.mass >= 0.01f)
  6975. {
  6976. //print("this is an Incendiary hit!");
  6977.  
  6978. GameObject fxFireInstance = new GameObject();
  6979.  
  6980. try
  6981. {
  6982.  
  6983. fxFireInstance = GameDatabase.Instance.GetModel("IDSkillfulR1/Effects/largeGFire/model");
  6984. }
  6985. catch
  6986. {
  6987. print("Problem locating fireFX");
  6988. }
  6989.  
  6990. if (fxFireInstance != null)
  6991. {
  6992. fxFireInstance.SetActive(true);
  6993. fxFireInstance.transform.position = this.transform.position;
  6994. fxFireInstance.transform.LookAt(FlightGlobals.ActiveVessel.mainBody.transform);
  6995.  
  6996. terrainBurner tB = fxFireInstance.AddComponent<terrainBurner>();
  6997. tB.throwsHeat = 100f;
  6998. tB.heatRange = rb.mass * 80f;
  6999.  
  7000. Destroy(fxFireInstance, 300f * (float)rndNumber.rndDouble(0.75, 2.5));
  7001. }
  7002.  
  7003.  
  7004. }
  7005.  
  7006. Destroy(this.gameObject);
  7007. }
  7008.  
  7009. }
  7010.  
  7011.  
  7012. public class gunDirector : PartModule
  7013. {
  7014.  
  7015. public float lastShotDistance = 0f;//maybe use these later.
  7016. public float lastShotElevation = 0f;
  7017.  
  7018. [KSPField(isPersistant=true,guiActive=true)]
  7019. public bool inAction = true;
  7020.  
  7021. public void FixedUpdate()
  7022. {
  7023. //something here
  7024. }
  7025.  
  7026. public void doRangeMessage(float rangeMsg)
  7027. {
  7028.  
  7029. }
  7030.  
  7031. public void ApplyDamage(float damageState)
  7032. {
  7033. float chanceBroken = rndNumber.rndRoll(0, 100);
  7034. if (chanceBroken < 5f)
  7035. {
  7036. inAction = false;
  7037.  
  7038.  
  7039.  
  7040. }
  7041.  
  7042. if (damageState < 1f)
  7043. {
  7044. //this.origRange *= damageState;
  7045. }
  7046. if (damageState == 1f)
  7047. {
  7048. inAction = true;
  7049. }
  7050. }
  7051.  
  7052. }
  7053. //class turretControllerGUI
  7054. //{
  7055. // public Rect windowRect = new Rect(500f, 200f, 150f, 30f);
  7056. // public int windowID;
  7057. // public Vector2 buttonSize = new Vector2(30f, 30f);
  7058. // public float padding = 8f;
  7059. // public Rect drawPosition = new Rect(0f, 0f, 30f, 30f);
  7060.  
  7061. // private GUIStyle buttonPassive;
  7062. // private GUIStyle buttonActive;
  7063. // private bool stylesCreated = false;
  7064. // public bool turretSummonsYou = false;
  7065.  
  7066. // private Color faintBlack = new Color(0f, 0f, 0f, 0.1f);
  7067. // private Color opaqueBlack = new Color(0f, 0f, 0f, 1f);
  7068.  
  7069. // private void createStyles()
  7070. // {
  7071. // buttonPassive = new GUIStyle(GUI.skin.button);
  7072. // buttonActive = new GUIStyle(GUI.skin.button);
  7073.  
  7074. // buttonPassive.normal.textColor = Color.gray;
  7075. // buttonActive.normal.textColor = Color.white;
  7076.  
  7077. // buttonPassive.normal.background = new Texture2D(1, 1);
  7078. // buttonPassive.normal.background.SetPixel(0, 0, faintBlack);
  7079. // buttonPassive.normal.background.Apply();
  7080.  
  7081. // buttonActive.normal.background = new Texture2D(1, 1);
  7082. // buttonActive.normal.background.SetPixel(0, 0, opaqueBlack);
  7083. // buttonActive.normal.background.Apply();
  7084.  
  7085. // buttonPassive.padding = new RectOffset(2, 2, 2, 2);
  7086. // buttonActive.padding = new RectOffset(2, 2, 2, 2);
  7087.  
  7088. // stylesCreated = true;
  7089. // }
  7090.  
  7091. // private GUIStyle getButtonStyle(KeyCode key)
  7092. // {
  7093. // if (Input.GetKey(key))
  7094. // return buttonActive;
  7095. // else
  7096. // return buttonPassive;
  7097. // }
  7098.  
  7099. // private GUIStyle getButtonStyle(bool state)
  7100. // {
  7101. // if (state)
  7102. // return buttonActive;
  7103. // else
  7104. // return buttonPassive;
  7105. // }
  7106.  
  7107. // private Rect longButtonRect(float length)
  7108. // {
  7109. // return new Rect(drawPosition.x, drawPosition.y, buttonSize.x * length, buttonSize.y);
  7110. // }
  7111.  
  7112. // public turretControllerGUI()
  7113. // {
  7114. // windowID = 13434;
  7115. // }
  7116.  
  7117. // private void nextButtonPos()
  7118. // {
  7119. // drawPosition.x += buttonSize.x + padding;
  7120. // }
  7121.  
  7122. // private void newLine(float x)
  7123. // {
  7124. // drawPosition.x = x;
  7125. // drawPosition.y += buttonSize.y + padding;
  7126. // }
  7127.  
  7128. // public void drawWindow(int ID)
  7129. // {
  7130. // GUI.DragWindow();
  7131. // }
  7132.  
  7133. // public void OnGUI()
  7134. // {
  7135. // if (turretSummonsYou == true)
  7136. // {
  7137. // if (!stylesCreated)
  7138. // createStyles();
  7139. // windowRect = GUI.Window(windowID, windowRect, drawWindow, "Input Visualizer", buttonActive);
  7140.  
  7141. // float letterKeysXpos = windowRect.x + buttonSize.x * 2 + padding * 2;
  7142. // drawPosition.x = letterKeysXpos;
  7143. // drawPosition.y = windowRect.y + windowRect.height + padding;
  7144.  
  7145. // GUI.Button(drawPosition, "Q", getButtonStyle(KeyCode.Q));
  7146. // nextButtonPos();
  7147. // GUI.Button(drawPosition, "W", getButtonStyle(KeyCode.W));
  7148. // nextButtonPos();
  7149. // GUI.Button(drawPosition, "E", getButtonStyle(KeyCode.E));
  7150. // newLine(letterKeysXpos);
  7151.  
  7152. // GUI.Button(drawPosition, "A", getButtonStyle(KeyCode.A));
  7153. // nextButtonPos();
  7154. // GUI.Button(drawPosition, "S", getButtonStyle(KeyCode.S));
  7155. // nextButtonPos();
  7156. // GUI.Button(drawPosition, "D", getButtonStyle(KeyCode.D));
  7157. // newLine(letterKeysXpos);
  7158.  
  7159. // GUI.Button(drawPosition, "Z", getButtonStyle(KeyCode.Z));
  7160. // nextButtonPos();
  7161. // GUI.Button(drawPosition, "X", getButtonStyle(KeyCode.X));
  7162. // nextButtonPos();
  7163. // GUI.Button(drawPosition, "C", getButtonStyle(KeyCode.C));
  7164. // newLine(letterKeysXpos);
  7165.  
  7166. // drawPosition.x = windowRect.x;
  7167. // drawPosition.y = windowRect.y + windowRect.height + padding * 2 + buttonSize.y;
  7168. // GUI.Button(longButtonRect(2), "Caps", getButtonStyle(KeyCode.CapsLock));
  7169. // drawPosition.y += buttonSize.y + padding;
  7170. // GUI.Button(longButtonRect(2), "Shift", getButtonStyle(KeyCode.LeftShift));
  7171. // drawPosition.y += buttonSize.y + padding;
  7172. // GUI.Button(longButtonRect(2), "Ctrl", getButtonStyle(KeyCode.LeftControl));
  7173. // }
  7174. // }
  7175. //}
  7176.  
  7177. public class checkElectricity : MonoBehaviour
  7178. {
  7179.  
  7180. public static float useElectricCharge(Part basePart, double useCharge)
  7181. {
  7182. double getCharge;
  7183.  
  7184.  
  7185. getCharge = basePart.RequestResource("ElectricCharge", useCharge);
  7186. if (getCharge > 0f)
  7187. {
  7188. double resourceReceived = getCharge / useCharge;
  7189. float finalUsedOutput = Mathf.Clamp((float)resourceReceived, 0f, 1f);
  7190. return finalUsedOutput;
  7191. }
  7192. else
  7193. {
  7194. return 0.0f;
  7195. }
  7196.  
  7197. }
  7198.  
  7199. }
  7200.  
  7201. public class endFx : MonoBehaviour
  7202. {
  7203. public GameObject thisObject;
  7204.  
  7205. public float endTime = 2f;
  7206.  
  7207. KSPParticleEmitter[] thisKPE;
  7208.  
  7209. public void Start()
  7210. {
  7211. thisObject = this.gameObject;
  7212. Invoke("StopEmitter", endTime);
  7213.  
  7214. }
  7215.  
  7216.  
  7217. public void StopEmitter()
  7218. {
  7219.  
  7220. thisKPE = base.GetComponentsInChildren<KSPParticleEmitter>();
  7221. if (thisKPE != null)
  7222. {
  7223. //print("Number of KSPParticleEmitters: " + thisKPE.Length);
  7224. if (thisKPE.Length > 1)
  7225. {
  7226. for (int i = 0; i < thisKPE.Length; i++)
  7227. {
  7228. thisKPE[i].emit = false;
  7229. }
  7230. }
  7231.  
  7232. }
  7233.  
  7234.  
  7235. //print("Stopped emitting after " + endTime + " seconds!");
  7236. }
  7237.  
  7238. }
  7239. ****end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement