Jump to content

Search the Community

Showing results for tags 'warpgate'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements
    • Welcome Aboard
  • Kerbal Space Program 1
    • KSP1 Discussion
    • KSP1 Suggestions & Development Discussion
    • KSP1 Challenges & Mission ideas
    • KSP1 The Spacecraft Exchange
    • KSP1 Mission Reports
    • KSP1 Gameplay and Technical Support
    • KSP1 Mods
    • KSP1 Expansions
  • Kerbal Space Program 2
    • KSP2 Dev Updates
    • KSP2 Discussion
    • KSP2 Suggestions and Development Discussion
    • Challenges & Mission Ideas
    • The KSP2 Spacecraft Exchange
    • Mission Reports
    • KSP2 Prelaunch Archive
  • Kerbal Space Program 2 Gameplay & Technical Support
    • KSP2 Gameplay Questions and Tutorials
    • KSP2 Technical Support (PC, unmodded installs)
    • KSP2 Technical Support (PC, modded installs)
  • Kerbal Space Program 2 Mods
    • KSP2 Mod Discussions
    • KSP2 Mod Releases
    • KSP2 Mod Development
  • Community
    • Science & Spaceflight
    • Kerbal Network
    • The Lounge
    • KSP Fan Works
  • International
    • International

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Skype


Twitter


About me


Location


Interests

Found 1 result

  1. Building a stargate mod to learn C# So im using this mod as a base. Jumpdrive mod I have gotten to the point where I have learned the basics. It functions just as the original mod did with some superficial changes just to understand how things worked. It builds and works successful as the original mod did. You activate the gate (Jump Beacon), then activate the DHD (Jump Drive) and choose your destination and then warp there. Now what I want to do is have a single separate part, a ring warpgate (Stargate) that you activate with a DHD attached to your ship. The DHD selects a destination. Then you fly into the ring and it warps you to the center of the gate you selected at the same velocity you went through the other one. Currently the code is changing the mass of the parts on activate and I cannot find how its doing that. Can anyone help? using KSP.IO; using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; namespace KSP_Frizz_Warpgate { /// <summary> /// Jump Drive plugin. When a Jump Drive is activated and given a target, it /// spools up a "jump charge" and then teleports to a point near the target. /// </summary> public class DHD_Drive : PartModule { Vessel target; bool activated = false; Rect windowPos; Dictionary<Vessel, string> targets; AnimationState jumpAnimation; int resolution = -1; [KSPField(isPersistant = false, guiActive = true, guiName = "Charge Rate")] public float chargeRate = 0.1f; [KSPField(isPersistant = false, guiActive = true, guiName = "Power Consumption Rate")] public float powerConsumptionRate = 10f; public override void OnStart(StartState state) { RenderingManager.AddToPostDrawQueue(998, new Callback(drawGUI)); } private void mainGUI(int windowID) { GUILayout.BeginVertical(HighLogic.Skin.scrollView); if (targets.Count() <= 0) GUILayout.Label("No active Warpgate beacons found."); else foreach (KeyValuePair<Vessel, string> line in targets) { if (GUILayout.Button(line.Key.vesselName + line.Value, HighLogic.Skin.button)) { print(line.Key.vesselName + " selected as target."); target = line.Key; } } GUILayout.EndVertical(); if (GUILayout.Button("Cancel", HighLogic.Skin.button)) Abort(); GUI.DragWindow(); } protected void drawGUI() { if (activated && target == null) windowPos = GUILayout.Window(997, windowPos, mainGUI, "Select a Warpgate target", HighLogic.Skin.window, GUILayout.MinWidth(240), GUILayout.MinHeight(160)); } public override void OnFixedUpdate() { if (target != null && activated && vessel.packed == false) { if (part.Resources["JumpCharge"].amount >= part.Resources["JumpCharge"].maxAmount) { //if there is a full jump charge and a target has been selected, jump Jump(); } else { //if there is not a full jump charge, check whether enough electric charge is available float required = (float)((1f + part.Resources["JumpCharge"].amount * 0.1f) * powerConsumptionRate); if (part.RequestResource("ElectricCharge", required) < required) { Abort(); return; } //if enough electric charge is available, consume electric charge to charge the jump part.Resources["JumpCharge"].amount += required * chargeRate; //animate the gimbal rings jumpAnimation.normalizedTime = (float)part.Resources["JumpCharge"].amount / (float)part.Resources["JumpCharge"].maxAmount; } } } [KSPAction("ActionActivate", KSPActionGroup.None, guiName = "Activate")] public void ActionActivate(KSPActionParam param) { Activate(); } [KSPEvent(name = "Activate", active = true, guiActive = true, guiName = "Activate")] public void Activate() { part.force_activate(); ListTargets(); activated = true; //prepare the jump animation jumpAnimation = part.FindModelAnimators("Jump").FirstOrDefault()["Jump"]; jumpAnimation.speed = 0f; jumpAnimation.weight = 1f; jumpAnimation.enabled = true; windowPos = new Rect(Screen.width * 0.5f - 120, Screen.height * 0.5f - 80, 1, 1); part.Effect("JumpCharge"); Events["Abort"].active = true; Events["Activate"].active = false; } [KSPEvent(name = "Abort", active = false, guiActive = true, guiName = "Cancel Jump")] public void Abort() { activated = false; part.Resources["ElectricCharge"].amount = part.Resources["JumpCharge"].amount; part.Resources["JumpCharge"].amount = 0; target = null; Events["Activate"].active = true; Events["Abort"].active = false; part.Effect("Abort"); //Reset the animation jumpAnimation.normalizedTime = 0f; print("Jump canceled."); } public void Jump() { print("Jumping..."); // Discharge and stop charging activated = false; part.Resources["JumpCharge"].amount = 0; foreach (Part p in vessel.parts) { if (p.Resources["ElectricCharge"] != null) p.Resources["ElectricCharge"].amount = p.Resources["ElectricCharge"].amount * 0.1f; //Do not destroy solar pannels that are deployed!!! /* foreach (PartModule m in p.Modules) { if (m.moduleName == "ModuleDeployableSolarPanel") { if (m.Fields["stateString"].GetValue<String>(m) == "EXTENDED" && m.Fields["isBreakable"].GetValue<bool>(m)) //Break any solar panels that were carelessly left open m.BroadcastMessage("breakPanels"); } }*/ } part.Resources["ElectricCharge"].amount = part.Resources["ElectricCharge"].maxAmount; //Reset the animation jumpAnimation.normalizedTime = 0f; // Disable Physics, etc. vessel.Landed = false; vessel.Splashed = false; vessel.landedAt = string.Empty; OrbitPhysicsManager.HoldVesselUnpack(180); vessel.GoOnRails(); vessel.situation = Vessel.Situations.ORBITING; // Prepare special orbital parameters. Vector3d error = UnityEngine.Random.onUnitSphere + UnityEngine.Random.insideUnitSphere * 0.5f; if (hasBeacon(target, true)) { if (resolution >= 0) { print("Resolution successfully retrieved: " + resolution.ToString()); error *= (float)resolution; } else { print("Resolution could not be retrieved, using default value of 100"); error *= 100f; } } else { print("Error! Somehow an invalid target was selected."); } if (target.situation == Vessel.Situations.PRELAUNCH) { print("Jumps to prelaunch gates are not permitted, so the jump has been canceled."); } else { // Set the vessel's orbital parameters to match the target's. vessel.orbit.UpdateFromStateVectors(target.orbit.pos + error, target.orbit.vel, target.mainBody, Planetarium.GetUniversalTime()); vessel.orbit.Init(); vessel.orbit.UpdateFromUT(Planetarium.GetUniversalTime()); vessel.orbitDriver.pos = vessel.orbit.pos.xzy; vessel.orbitDriver.vel = vessel.orbit.vel; } // Make gratuitous booming noise!!!11!!!!!1 part.Effect("Jump"); // Finish the jump if (resolution > 10) vessel.SetRotation(UnityEngine.Random.rotation); else vessel.SetRotation(target.GetTransform().rotation); vessel.angularMomentum = Vector3.zero; vessel.angularVelocity = Vector3.zero; target = null; Events["Activate"].active = true; Events["Abort"].active = false; print("The jump has been completed. Now at " + vessel.mainBody); } void ListTargets() { if (targets == null) targets = new Dictionary<Vessel, string>(); targets.Clear(); foreach (Vessel ship in FlightGlobals.Vessels) { if (ship == vessel || ship == FlightGlobals.ActiveVessel) continue; if (ship.situation == Vessel.Situations.SPLASHED) continue; if (hasBeacon(ship) == false) continue; string info = " ("; switch (ship.situation) { // Describe the ship's situation case Vessel.Situations.LANDED: info += "On " + ship.mainBody.name + "'s surface"; break; case Vessel.Situations.SPLASHED: info += "Floating in " + ship.mainBody.name + "'s water"; break; case Vessel.Situations.PRELAUNCH: goto case Vessel.Situations.LANDED; default: info += "Orbiting " + ship.mainBody.name; break; } info += ")"; targets.Add(ship, info); } } bool hasBeacon(Vessel ship, bool fetchResolution = false) { if (ship.loaded) return false; foreach (ProtoPartSnapshot p in ship.protoVessel.protoPartSnapshots) { foreach (ProtoPartModuleSnapshot m in p.modules) { if (m.moduleName == "WarpgateBeacon") { print(ship.name + " has a " + p.partName + " part that contains a Warpgate DHD"); if (bool.Parse(m.moduleValues.GetValue("activated"))) { print("...and the Warpgate is ready to receive jumps. Proceeding..."); if (fetchResolution) { print("Fetching resolution..."); resolution = int.Parse(m.moduleValues.GetValue("resolution")); } return true; } print("...but the Warpgate appears to be inactive."); // } } } return false; } } } I just answered my own question, the JumpCharge resource has mass. Can I set that to 0 without damage? I guess I could get rid of it and have it use just strait electricity....
×
×
  • Create New...