Search the Community
Showing results for tags 'stargate'.
-
Hi all, As my other thread evolved into what this thread was always meant to be (eventually), I figured I'd just jump right in and make my Mod Development thread. I will have a lot of questions as I am still getting my head around how c# and the api works. I have created a Git repository for the Mod as it currently is (or rather isn't, nothing quite works yet), but it will make things easier than me pasting code all the time The readme has some basic information about the mod and what I'm looking to achieve, the readme itself is still a work in progress so may have some bits missing. https://github.com/TheMightySpud/TMS_Orbital_Mechanics This is just the introductory post, I'll be adding more and having breakdowns/tantrums in other posts further down the line when things go horribly wrong So, on with the show as they say. TheMightySpud
-
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....
- 1 reply
-
- learning c#
- stargate
-
(and 1 more)
Tagged with:
-
So I've decided to officially put it out there that I am looking for people to help me with this set of projects. This is my first project and i have zero experience in modelling and programming. I have a working knowledge of both, maybe programming moreso but I really have my heart set on this project and want to get it out there for everyone else to enjoy. If you have experience and would like to see this project come to fruition then please feel free to let me know! First priority is Destiny however secondary to this will be Destiny's Shuttle, Daedlus + X302's, and as a side project + hobby the puddlejumper from sg-atlantis. If these projects are completed then I 'may' look into doing more ships from the stargate series, depending on interest and support. Here is a link to my first thread and it details my idea's and what i've learnt so far modelling so feel free to take a good look and see what i plan to do. Also if you don't have experience but do have an idea, this is the place to put it out there Link: http://kerbalspaceprogram.com/forum/showthread.php/16096-Starting-a-new-project-and-need-advice Thanks and I hope to see more of you here soon
-
I know it's over-ambitious considering i've never made any models or had much graphics program use but i want to make a scaled down and simplified version of both daedlus from the Stargate-SG1/Atlantis series and the same for Destiny from Stargate universe. Would someone possibly tell me what programs i need (that are user friendly) and which are free, as this is a hobby and i don't have money to throw away. I'll try going into it and learn as i go and if i have any future questions ill post here but i really need to know what program to get me started, which also makes scaling the model specifically for this game, easier. Thank you in advance to all who can help