private void OnCollisionIgnoreUpdate() { VesselList vesselList = GetAllVesselColliders(); // Iterate through the created list of vessels/parts/colliders and enable collisions between them for (int v1 = 0; v1 < vesselList.vesselList.Count; v1++) { for (int v2 = v1; v2 < vesselList.vesselList.Count; v2++) { VesselList.VesselInfo vessel1 = vesselList.vesselList[v1]; VesselList.VesselInfo vessel2 = vesselList.vesselList[v2]; for (int p1 = 0; p1 < vessel1.partList.Count; p1++) { VesselList.VesselInfo.PartInfo part1 = vessel1.partList[p1]; for (int p2 = p1 + 1; p2 < vessel2.partList.Count; p2++) { VesselList.VesselInfo.PartInfo part2 = vessel2.partList[p2]; bool ignore = false; if (vessel1 == vessel2) { /* * bool adjacent = false; * // Enable collisions for adjacent parts? * if (part1.part.parent == part2.part || * part2.part.parent == part1.part) * adjacent = true; */ // A matrix enabling collisions depending on the settings of the two parts bool[][] active = new bool[][] { /* * new bool[] { false, false, !adjacent, true}, * new bool[] { false, true, !adjacent, true }, * new bool[] { !adjacent, !adjacent, !adjacent, true }, * new bool[] { true, true, true, true }, */ new bool[] { false, false, true }, new bool[] { false, true, true }, new bool[] { true, true, true }, }; if (!active[(int)part1.collisionMode][(int)part2.collisionMode]) { ignore = true; } } for (int c1 = 0; c1 < part1.colliderList.Count; c1++) { for (int c2 = 0; c2 < part2.colliderList.Count; c2++) { Collider collider1 = part1.colliderList[c1]; Collider collider2 = part2.colliderList[c2]; Physics.IgnoreCollision(collider1, collider2, ignore); } } } } } } }
// Gather up info on all colliders in physics range and order them private VesselList GetAllVesselColliders() { VesselList vesselList = new VesselList(); vesselList.vesselList.Clear(); // Not sure why we want to do this... bool hasEVA = false; foreach (Vessel vessel in FlightGlobals.VesselsLoaded) { if (vessel.isEVA) { hasEVA = true; } } // Iterate through vessels in physics range, parts, and colliders foreach (Vessel vessel in FlightGlobals.VesselsLoaded) { VesselList.VesselInfo vesselInfo = new VesselList.VesselInfo(); vesselInfo.vessel = vessel; vesselList.vesselList.Add(vesselInfo); foreach (Part part in vessel.parts) { VesselList.VesselInfo.PartInfo partInfo = new VesselList.VesselInfo.PartInfo(); partInfo.part = part; vesselInfo.partList.Add(partInfo); // Check if there is an MechanicsToolkit part module in this part partInfo.collisionMode = 0; foreach (PartModule partModule in part.Modules) { if (partModule.moduleName == "MechanicsToolkit") { MechanicsToolkit mechanicsToolkit = (MechanicsToolkit)partModule; partInfo.collisionMode = mechanicsToolkit.collisionMode; } } Collider[] componentsInChildren = part.partTransform.GetComponentsInChildren <Collider>(hasEVA); if (componentsInChildren != null) { for (int k = 0; k < componentsInChildren.Length; k++) { Collider collider = componentsInChildren[k]; bool addCollider = (collider.gameObject.activeInHierarchy && collider.enabled) || ((hasEVA && (collider.tag == "Ladder" || collider.tag == "Airlock"))); if (addCollider) { partInfo.colliderList.Add(collider); } } } } } return(vesselList); }
private void FromXml_Version_1_56(XmlDocument xDoc) { XmlNodeList xNodeList; HullRace race; Vessel vessel; BeamPort bp; DronePort dp; EnginePort ep; ImpulsePoint ip; ManeuverPoint mp; xNodeList = xDoc.GetElementsByTagName("hullRace"); foreach (XmlNode node in xNodeList) { race = new HullRace(); foreach (XmlAttribute att in node.Attributes) { switch (att.Name) { case "ID": race.ID = att.Value; break; case "name": race.name = att.Value; if (!RaceNames.Contains(race.name)) { RaceNames.Add(race.name); } break; case "keys": foreach (string s in att.Value.Split(' ')) { race.keys.Add(s); if (!RaceKeys.Contains(s)) { RaceKeys.Add(s); } } break; } } if (String.IsNullOrEmpty(race.ID)) { continue; } HullRaceList.Add(race.ID, race); } RaceNamesSortedByLength = RaceNames.ToList(); RaceNamesSortedByLength.Sort(new Comparison <string>((string a, string b) => { int diff = b.Split(' ').Length - a.Split(' ').Length; if (diff != 0) { return(diff); } return(String.Compare(a, b)); } )); xNodeList = xDoc.GetElementsByTagName("vessel"); foreach (XmlNode node in xNodeList) { vessel = new Vessel(); foreach (XmlAttribute att in node.Attributes) { switch (att.Name) { case "uniqueID": vessel.uniqueID = att.Value; break; case "side": vessel.side = att.Value; break; case "classname": vessel.classname = att.Value; if (!VesselClassNames.Contains(vessel.classname)) { VesselClassNames.Add(vessel.classname); } break; case "broadType": vessel.broadType = att.Value; foreach (string broadType in vessel.broadType.Split(' ')) { if (!VesselBroadTypes.Contains(broadType)) { VesselBroadTypes.Add(broadType); } } break; } } if (String.IsNullOrEmpty(vessel.uniqueID)) { continue; } foreach (XmlNode subNode in node.ChildNodes) { switch (subNode.Name) { case "art": foreach (XmlAttribute att in node.Attributes) { switch (att.Name) { case "meshfile": vessel.meshfile = att.Value; break; case "diffuseFile": vessel.diffuseFile = att.Value; break; case "glowFile": vessel.glowFile = att.Value; break; case "specularFile": vessel.specularFile = att.Value; break; case "scale": vessel.scale = Helper.StringToDouble(att.Value); break; case "pushRadius": vessel.pushRadius = Helper.StringToDouble(att.Value); break; } } break; case "shields": foreach (XmlAttribute att in node.Attributes) { switch (att.Name) { case "front": vessel.shields_front = Helper.StringToDouble(att.Value); break; case "back": vessel.shields_back = Helper.StringToDouble(att.Value); break; } } break; case "carrier": foreach (XmlAttribute att in node.Attributes) { switch (att.Name) { case "compliment": vessel.carrier_compliment = Helper.StringToDouble(att.Value); break; } } break; case "performance": foreach (XmlAttribute att in node.Attributes) { switch (att.Name) { case "turnrate": vessel.preformance_turnrate = Helper.StringToDouble(att.Value); break; case "topspeed": vessel.preformance_topspeed = Helper.StringToDouble(att.Value); break; } } break; case "fleet_ai": foreach (XmlAttribute att in node.Attributes) { switch (att.Name) { case "commonality": vessel.fleet_ai_commonality = Helper.StringToDouble(att.Value); break; } } break; case "beam_port": bp = new BeamPort(); foreach (XmlAttribute att in subNode.Attributes) { switch (att.Name) { case "x": bp.x = Helper.StringToDouble(att.Value); break; case "y": bp.y = Helper.StringToDouble(att.Value); break; case "z": bp.z = Helper.StringToDouble(att.Value); break; case "range": bp.range = Helper.StringToDouble(att.Value); break; case "damage": bp.damage = Helper.StringToDouble(att.Value); break; case "cycletime": bp.cycletime = Helper.StringToDouble(att.Value); break; case "arcwidth": bp.arcwidth = Helper.StringToDouble(att.Value); break; } } vessel.beam_ports.Add(bp); break; case "drone_port": dp = new DronePort(); foreach (XmlAttribute att in subNode.Attributes) { switch (att.Name) { case "x": dp.x = Helper.StringToDouble(att.Value); break; case "y": dp.y = Helper.StringToDouble(att.Value); break; case "z": dp.z = Helper.StringToDouble(att.Value); break; case "range": dp.range = Helper.StringToDouble(att.Value); break; case "damage": dp.damage = Helper.StringToDouble(att.Value); break; case "cycletime": dp.cycletime = Helper.StringToDouble(att.Value); break; } } vessel.drone_ports.Add(dp); break; case "engine_port": ep = new EnginePort(); foreach (XmlAttribute att in subNode.Attributes) { switch (att.Name) { case "x": ep.x = Helper.StringToDouble(att.Value); break; case "y": ep.y = Helper.StringToDouble(att.Value); break; case "z": ep.z = Helper.StringToDouble(att.Value); break; } } vessel.engine_ports.Add(ep); break; case "impulse_point": ip = new ImpulsePoint(); foreach (XmlAttribute att in subNode.Attributes) { switch (att.Name) { case "x": ip.x = Helper.StringToDouble(att.Value); break; case "y": ip.y = Helper.StringToDouble(att.Value); break; case "z": ip.z = Helper.StringToDouble(att.Value); break; } } vessel.impulse_points.Add(ip); break; case "maneuver_point": mp = new ManeuverPoint(); foreach (XmlAttribute att in subNode.Attributes) { switch (att.Name) { case "x": mp.x = Helper.StringToDouble(att.Value); break; case "y": mp.y = Helper.StringToDouble(att.Value); break; case "z": mp.z = Helper.StringToDouble(att.Value); break; } } vessel.maneuver_points.Add(mp); break; } } VesselList.Add(vessel.uniqueID, vessel); } VesselClassNamesSortedByLength = VesselClassNames.ToList(); VesselClassNamesSortedByLength.Sort(new Comparison <string>((string a, string b) => { int diff = b.Split(' ').Length - a.Split(' ').Length; if (diff != 0) { return(diff); } return(String.Compare(a, b)); } )); }