/// <summary>Retrieves the dust colors which are stored in the DustColors-file and are auto-loaded by KSP.</summary> static void ReadDustColor() { bool error = false; // DustColors.cfg DustColors = new Dictionary <string, Dictionary <string, Color> >(); ConfigNode configFile = ConfigNode.Load(dustColorsFileName); ConfigNode configNode = configFile.GetNode("DustColorDefinitions"); if (Equals(configFile, null) || !configFile.HasNode("DustColorDefinitions")) // DustColorDefinitions node doesn't exist. { KFLog.Warning("DustColors.cfg is missing or damaged!"); error = true; } if (!error && (Equals(configNode, null) || Equals(configNode.CountNodes, 0))) { KFLog.Warning("Dust color definitions not found or damaged!"); error = true; } if (error) { dustConfigsPresent = false; return; } dustConfigsPresent = true; // Implied: "error" is false, which means the above two checks also returned false, // which means the file is there and properly formatted. foreach (ConfigNode celestialNode in configNode.GetNodes()) // For each celestial body do this: { var biomes = new Dictionary <string, Color>(); foreach (ConfigNode biomeNode in celestialNode.GetNodes()) // For each biome of that celestial body do this: { float r = 0f; float.TryParse(biomeNode.GetValue("Color").Split(',')[0], out r); float g = 0f; float.TryParse(biomeNode.GetValue("Color").Split(',')[1], out g); float b = 0f; float.TryParse(biomeNode.GetValue("Color").Split(',')[2], out b); float a = 0f; float.TryParse(biomeNode.GetValue("Color").Split(',')[3], out a); biomes.Add(biomeNode.name, new Color(r, g, b, a)); } DustColors.Add(celestialNode.name, biomes); if (Equals(biomes.Count, 0)) { KFLog.Error(string.Format("No biome colors found for {0}!", celestialNode.name)); } else { KFLog.Log(string.Format("Found {0} biome color definitions for {1}.", biomes.Count, celestialNode.name)); } } }
public void StartUp() { #if DEBUG KFLog.Warning("ModuleCamerashot Start"); #endif if (!Equals(KFPersistenceManager.cameraRes, null)) { fResWidth = KFPersistenceManager.cameraRes; fResHeight = KFPersistenceManager.cameraRes; } if (!Equals(KFPersistenceManager.cameraFramerate, null)) { fFrameThreshHold = KFPersistenceManager.cameraFramerate; } _vessel = GetComponent <Vessel>(); foreach (Part PA in _vessel.parts) { // disable UnusedVariable.Compiler foreach (KFRepulsor RA in PA.GetComponentsInChildren <KFRepulsor>()) { kFPartCount++; } foreach (KFModuleWheel RA in PA.GetComponentsInChildren <KFModuleWheel>()) { kFPartCount++; } } if (kFPartCount > 1) { #if DEBUG KFLog.Log("Starting camera"); #endif _cameraObject = new GameObject("ColourCam"); _cameraObject.transform.parent = _vessel.transform; _cameraObject.transform.LookAt(_vessel.mainBody.transform.position); _cameraObject.transform.Translate(new Vector3(0, 0, -10)); _camera = _cameraObject.AddComponent <Camera>(); _camera.targetTexture = renderTexture; _camera.cullingMask = cameraMask; _camera.enabled = false; renderTexture = new RenderTexture(Convert.ToInt32(fResWidth), Convert.ToInt32(fResHeight), 24); groundShot = new Texture2D(Convert.ToInt32(fResWidth), Convert.ToInt32(fResHeight), TextureFormat.RGB24, false); dustCamEnabled = KFPersistenceManager.isDustCameraEnabled; isReady = true; } }
public override void OnStart(PartModule.StartState state) { base.OnStart(state); Transform destroyedObject = transform.Search(objectName); if (!Equals(destroyedObject, null)) { UnityEngine.Object.Destroy(destroyedObject.gameObject); #if DEBUG KFLog.Log(string.Format("Destroying: {0}", objectName)); #endif } else { KFLog.Warning(string.Format("Could not find object named \"{0}\" to destroy.", objectName)); } }
public override void OnUpdate() { base.OnUpdate(); float fResourceConsumption, fRequestedResource; if (repulsorMode) { fResourceConsumption = (fRepulsorHeight / 2) * (1 + _moduleWheel.fSpringRate) * Time.deltaTime * resourceConsumptionRate; effectPower = fResourceConsumption / effectPowerMax; KFLog.Log(string.Format("\"effectPower\" = {0}", effectPower)); fRequestedResource = part.RequestResource(resourceName, fResourceConsumption); if (fRequestedResource < (fResourceConsumption * 0.9f)) { #if DEBUG KFLog.Warning(string.Format("Retracting due to low \"{0}.\"", resourceName)); #endif lowResource = true; fRepulsorHeight = 0; UpdateColliders("wheel"); _moduleWheel.status = Equals(resourceName, "ElectricCharge") ? "Low Charge" : _moduleWheel.statusLowResource; } else { lowResource = false; _moduleWheel.status = _moduleWheel.statusNominal; } } else { effectPower = 0; } RepulsorSound(); effectPower = 0; }
public override void OnStart(PartModule.StartState state) { base.OnStart(state); if (HighLogic.LoadedSceneIsFlight && !Equals(vessel.vesselType, VesselType.Debris)) { GameEvents.onGamePause.Add(OnPause); GameEvents.onGameUnpause.Add(OnUnPause); _moduleWheel = part.GetComponentInChildren <KFModuleWheel>(); if (!Equals(_moduleWheel, null)) { tweakScaleCorrector = _moduleWheel.tweakScaleCorrector; } KFLog.Warning(string.Format("TS Corrector: {0}", tweakScaleCorrector)); colliderList = colliderNames.SplitString(); for (int i = 0; i < colliderList.Count(); i++) { colliders.Add(transform.SearchStartsWith(colliderList[i]).GetComponent <WheelCollider>()); objectCount++; } susTrav = transform.SearchStartsWith(susTravName); initialPosition = susTrav.localPosition; susTravIndex = susTravAxis.SetAxisIndex(); MoveSuspension(susTravIndex, -fLastFrameTraverse, susTrav); if (objectCount > 0) { StartCoroutine("WaitAndStart"); } else { KFLog.Error("KFSuspension not configured correctly"); } } }
public override void OnStart(PartModule.StartState state) { _KFModuleWheel = part.GetComponentInChildren <KFModuleWheel>(); tweakScaleCorrector = _KFModuleWheel.tweakScaleCorrector; if (!isConfigured) { foreach (WheelCollider wc in part.GetComponentsInChildren <WheelCollider>()) { if (wc.name.StartsWith(colliderName, StringComparison.Ordinal)) { _wheelCollider = wc; fSuspensionDistance = wc.suspensionDistance; #if DEBUG KFLog.Log(string.Format("SuspensionDistance is: {0}.", suspensionDistance)); #endif isConfigured = true; } } } if (HighLogic.LoadedSceneIsFlight && !Equals(vessel.vesselType, VesselType.Debris)) { GameEvents.onGamePause.Add(new EventVoid.OnEvent(OnPause)); GameEvents.onGameUnpause.Add(new EventVoid.OnEvent(OnUnPause)); // Find named onjects in part. foreach (WheelCollider wc in part.GetComponentsInChildren <WheelCollider>()) { if (wc.name.StartsWith(colliderName, StringComparison.Ordinal)) { _wheelCollider = wc; } } foreach (Transform tr in part.GetComponentsInChildren <Transform>()) { if (tr.name.StartsWith(wheelName, StringComparison.Ordinal)) { _wheel = tr; } if (tr.name.StartsWith(steeringName, StringComparison.Ordinal)) { _trackSteering = tr; } if (tr.name.StartsWith(sustravName, StringComparison.Ordinal)) { _susTrav = tr; } } initialPosition = _susTrav.localPosition; susTravIndex = susTravAxis.SetAxisIndex(); steeringIndex = steeringAxis.SetAxisIndex(); if (_KFModuleWheel.hasSteering) { initialSteeringAngles = _trackSteering.transform.localEulerAngles; #if DEBUG KFLog.Log(string.Format("initial steering angles are \"{0}\"", initialSteeringAngles)); #endif } directionCorrector = useDirectionCorrector ? _KFModuleWheel.directionCorrector : 1; _wheelRotation = new Vector3(wheelRotationX, wheelRotationY, wheelRotationZ); if (Equals(lastFrameTraverse, 0)) //check to see if we have a value in persistance { #if DEBUG KFLog.Log("Last frame = 0. Setting suspension distance."); #endif lastFrameTraverse = _wheelCollider.suspensionDistance; } #if DEBUG KFLog.Log(string.Format("Last frame = {0}", lastFrameTraverse)); #endif couroutinesActive = true; MoveSuspension(susTravIndex, -lastFrameTraverse, _susTrav); //to get the initial stuff correct if (_KFModuleWheel.hasSteering) { StartCoroutine("Steering"); #if DEBUG KFLog.Log("Starting steering coroutine."); #endif } if (trackedWheel) { StartCoroutine("TrackedWheel"); } else { StartCoroutine("IndividualWheel"); } if (hasSuspension) { KFLog.Warning("KFWheel suspension module is deprecated. Please use KFSuspension."); StartCoroutine("Suspension"); } part.force_activate(); } base.OnStart(state); }
/// <summary>Configures the part for editor and flight.</summary> /// <remarks> /// Most importantly, it grabs a list of wheel colliders to be /// used later. Also configures visibility of tweakables, figures /// out the parts orientation and position in the vessel to calculate /// steering angles and sets some defaults. /// </remarks> /// <param name="state">Start state. Set by KSP to declare the scene it initializes this class in.</param> public override void OnStart(PartModule.StartState state) //when started { base.OnStart(state); fSusInc = KFPersistenceManager.suspensionIncrement; CustomResourceTextSetup(); fColliderMass = 10; var partOrientationForward = new Vector3(0f, 0f, 0f); var partOrientationRight = new Vector3(0f, 0f, 0f); var partOrientationUp = new Vector3(0f, 0f, 0f); if (!string.Equals(orientationObjectName, "Default")) { #if DEBUG KFLog.Warning("Setting transformed part orientation."); #endif partOrientationUp = transform.Search(orientationObjectName).up; partOrientationForward = transform.Search(orientationObjectName).forward; partOrientationRight = transform.Search(orientationObjectName).right; } else { #if DEBUG KFLog.Warning("Setting default part orientation."); #endif partOrientationUp = part.transform.up; partOrientationForward = part.transform.forward; partOrientationRight = part.transform.right; } if (hasRetractAnimation) { foreach (ModuleAnimateGeneric ma in part.FindModulesImplementing <ModuleAnimateGeneric>()) { ma.Actions["ToggleAction"].active = false; ma.Events["Toggle"].guiActive = false; ma.Events["Toggle"].guiActiveEditor = false; } SetupAnimation(); } //disables tweakables if being used on a passive part (mecannum wheel or skid, for example) if (disableTweakables) { KFLog.Warning("Disabling tweakables."); foreach (BaseField k in Fields) { #if DEBUG KFLog.Log(string.Format("Found {0}", k.guiName)); #endif k.guiActive = false; k.guiActiveEditor = false; } foreach (BaseAction a in Actions) { #if DEBUG KFLog.Log(string.Format("Found {0}", a.guiName)); #endif a.active = false; } foreach (BaseEvent e in Events) { #if DEBUG KFLog.Log(string.Format("Found {0}", e.guiName)); #endif e.active = false; } } if (fStartRetracted) { isRetracted = true; } if (!isRetracted) { fCurrentTravel = fRideHeight; //set up correct values from persistence } else { fCurrentTravel = 0f; } #if DEBUG KFLog.Log(string.Format("\"appliedRideHeight\" = {0}", appliedRideHeight)); #endif // Disable retract tweakables if retract option not specified. if (HighLogic.LoadedSceneIsEditor && !hasRetract) { part.DisableAnimateButton(); Actions["AGToggleDeployed"].active = false; Actions["Deploy"].active = false; Actions["Retract"].active = false; Fields["startRetracted"].guiActiveEditor = false; } if (HighLogic.LoadedSceneIsFlight && (!Equals(vessel.vesselType, VesselType.Debris) && !Equals(vessel.vesselType, VesselType.EVA))) { if (isDustEnabled) { _dustFX = part.gameObject.GetComponent <KFDustFX>(); if (Equals(_dustFX, null)) { _dustFX = part.gameObject.AddComponent <KFDustFX>(); _dustFX.OnStart(state); _dustFX.tweakScaleFactor = tweakScaleCorrector; } } fAppliedTravel = fRideHeight / 100f; StartCoroutine(StartupStuff()); maxRPM /= tweakScaleCorrector; fStartRetracted = false; if (!hasRetract) { part.DisableAnimateButton(); } // Wheel steering ratio setup rootIndexLong = WheelUtils.GetRefAxis(part.transform.forward, vessel.rootPart.transform); rootIndexLat = WheelUtils.GetRefAxis(part.transform.right, vessel.rootPart.transform); rootIndexUp = WheelUtils.GetRefAxis(part.transform.up, vessel.rootPart.transform); fSteeringRatio = WheelUtils.SetupRatios(rootIndexLong, part, vessel, fGroupNumber); GetControlAxis(); if (fTorque > 2f) { fTorque /= 100f; } wheelCount = 0; foreach (WheelCollider wheelCollider in part.GetComponentsInChildren <WheelCollider>()) { wheelCount++; JointSpring userSpring = wheelCollider.suspensionSpring; userSpring.spring = fSpringRate * tweakScaleCorrector; userSpring.damper = fDamperRate * tweakScaleCorrector; wheelCollider.suspensionSpring = userSpring; wheelCollider.suspensionDistance = wheelCollider.suspensionDistance * fAppliedTravel; wcList.Add(wheelCollider); suspensionDistance.Add(wheelCollider.suspensionDistance); wheelCollider.enabled = true; wheelCollider.gameObject.layer = 27; } if (brakesApplied) { fBrakeTorque = brakingTorque; // Were the brakes left applied? } if (isRetracted) { RetractDeploy("retract"); } isReady = true; } DestroyBounds(); SetupWaterSlider(); GameEvents.onGamePause.Add(OnPause); GameEvents.onGameUnpause.Add(OnUnpause); }