Jump to content

Tralfagar

Members
  • Posts

    78
  • Joined

  • Last visited

Everything posted by Tralfagar

  1. @JediMasterSterling1 I've been using the New Community API Documentation as well as the source code for a few mods. edit: Oops. I think I misunderstood. IIRC I only need references to Assembly-CSharp.dll, KSPUtil.dll, and UnityEngine.dll. But just in case, here are what I currently have enabled for the whole project (of which only some are needed): Assembly-CSharp.dll Assembly-CSharp-firstpass.dll KSPCore.dll KSPUtil.dll SaveUpgradeEnginePipeline.Core.dll UnityEngine.dll UnityEngine.UI.dll
  2. Hey! I know exactly how you feel. Modding KSP can feel...suffocating. Here's my current class for a GUI that I've been reverse-engineering. I hope it helps! using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using UnityEngine; using KSP; using KSP.UI.Screens;//required for ApplicationLauncherButton type namespace PopulationMod { [KSPAddon(KSPAddon.Startup.EveryScene, false)] public class PopModGUI : MonoBehaviour { internal static string assetFolder = "PopulationMod/CivilianManagement/Assets/"; private static ApplicationLauncherButton CivPopButton = null; static bool CivPopGUIOn = false; internal bool CivPopTooltip = false; private GUIStyle _windowstyle, _labelstyle; private bool hasInitStyles = false; private static ApplicationLauncherButton appButton = null; /// <summary> /// Awake this instance. Pre-existing method in Unity that runs before KSP loads. /// </summary> public void Awake() { //Debug.Log (debuggingClass.modName + "Starting Awake()");//What I am using to debug DontDestroyOnLoad(this); GameEvents.onGUIApplicationLauncherReady.Add(OnAppLauncherReady);//when AppLauncher can take apps, give it OnAppLauncherReady (mine) GameEvents.onGUIApplicationLauncherDestroyed.Add (OnAppLauncherDestroyed);//Not sure what this does } public void OnAppLauncherDestroyed(){ if (appButton != null){ OnToggleFalse (); ApplicationLauncher.Instance.RemoveApplication (appButton); } } /// <summary> /// Raises the app launcher ready event. Method to create an app button on the AppLauncher, as well as tell /// what/how the GUI is loaded. /// </summary> public void OnAppLauncherReady() { InitStyle(); string iconFile = "PopModIcon";//This is the name of the file that stores the mod's icon to be used in the appLauncher if (HighLogic.LoadedScene == GameScenes.SPACECENTER && appButton == null){//i.e. if running for the first time appButton = ApplicationLauncher.Instance.AddModApplication( OnToggleTrue, //Run OnToggleTrue() when user clicks button OnToggleFalse, //Run OnToggleFalse() when user clicks button again null, null, null, null, //do nothing during hover, exiting, enable/disable ApplicationLauncher.AppScenes.ALWAYS, //When to show applauncher/GUI button GameDatabase.Instance.GetTexture(assetFolder+iconFile , false));//where to look for mod applauncher icon //Debug.Log (debuggingClass.modName + "Finishing Awake()");//What I am using to debug } CivPopGUIOn = false; } /// <summary> /// Presumably what to do when the user opens/clicks the button. Called from OnAppLauncherReady. /// </summary> private static void OnToggleTrue() { //Debug.Log (debuggingClass.modName + "Starting OnToggleTrue()"); CivPopGUIOn = true;//turns on flag for GUI //Debug.Log (debuggingClass.modName + "Turning on GUI"); } /// <summary> /// Presumably what to do when the user closes the button. Called from OnAppLauncherReady. /// </summary> private static void OnToggleFalse() { //Debug.Log (debuggingClass.modName + "Starting OnToggleFalse()"); CivPopGUIOn = false;//turns off flag for GUI //Debug.Log (debuggingClass.modName + "Turning off GUI"); } /// <summary> /// I'm not sure what this is for...but it was already here and it seems to work. /// </summary> private void InitStyle() { _windowstyle = new GUIStyle(HighLogic.Skin.window); _labelstyle = new GUIStyle(HighLogic.Skin.label); hasInitStyles = true; } /// <summary> /// OnGUI() is called by the game and every time it refreshes the GUI. I just need it to check if the GUI is /// enabled and if it is, show it. /// </summary> public void OnGUI() {//Executes code whenever screen refreshes. Extension to enable use of button along main bar on top-right of screen. if (CivPopGUIOn) { PopulationManagementGUI ();//If button is enabled, display rectangle. }//end if }//end OnGui extension /// <summary> /// This method controls how the window actually looks when the HUD window is displayed. /// </summary> void PopulationManagementGUI(){ GUI.BeginGroup(new Rect(Screen.width / 2 - 250, Screen.height / 2 - 250, 500, 500)); GUILayout.BeginVertical("box"); GUILayout.Label("CIVPOP PlaceHolder GUI"); if (GUILayout.Button("Close this Window", GUILayout.Width(200f))) OnToggleFalse(); GUILayout.Label ("Can this display?"); GUILayout.EndVertical(); GUI.EndGroup(); } } } A quick note: I am using DebuggingClass to debug and it should be able to be ignored. Debug.Log ("message") prints its contents (message) to the KSP.log file.
  3. @blowfish thank you very much. I didn't realize I was barking up the wrong tree. I just read up on virtual methods and override and now it makes sense. OnStart within my class, CivilianPopulationRegulator, is an override method that overrides the OnStart that is inherited from BaseConverter. When the method is overridden, it is called as normal but the method statements are overridden. By using base.OnStart(state), the original OnStart method is called which does not have any of my modifications. Thank yoU!
  4. Hello all! I am working on reverse-engineering a mod and I have run into an issue with my understanding of C#. The mod has this method: public class CivilianPopulationRegulator : BaseConverter { public override void OnStart(PartModule.StartState state) { if (!HighLogic.LoadedSceneIsFlight) { base.OnStart(state); return; } if (this.vessel == null) { base.OnStart(state); return; } //do some stuff later base.OnStart(state);//Not sure what this does at the moment. } } Looking at the "base" keyword, it is used to call a method in the base class that is being overriden or it is used to call a constructor. Unless OnStart is a constructor, isn't this going into the extended class (BaseConverter, which extends PartModule) and run OnStart again? At the end of which, OnStart will be called yet again. And so on infinitely? So since the code is not infinitely recursive, I must be mistaken in either my understanding of OnStart or the "base" keyword. Would any of you guys know why this works and/or where I could learn more about this?
  5. Thank you very much for the replies. I agree that changing the enum may not work...but it doesn't look like it is necessary. Simply creating a new trait (below), Kerbals with title Test are spawning in the Astronaut Training Complex. It took me a little longer to understand what you guys were saying about creating custom classes, but I think I get it now. Since the above posts, I've been going through the documentation, trying to figure out how everything is connected and I think I got it. Here is what I've done so far: I modified Traits.cfg to include a new type of class similar to what @Aelfhe1m mentioned above: EXPERIENCE_TRAIT { name = Test title = Test desc = Pilots provide assistance in flying the vessel. EFFECT { name = CustomClass } } The biggest difference is that it should be calling "CustomClass" instead of "RepairSkill. I checked out the API for the autopilot/repair skills and it looks like they both extend the "Experience.ExperienceEffect" class. I thought it would be best to follow suit with mine: using System; using UnityEngine; using KSP; namespace PopulationMod { /// <summary> /// My custom trait to test feasibility of creating new traits. Right now, it looks like it spawns ~10% of the time in game. /// </summary> public class CustomClass : Experience.ExperienceTrait { public CustomClass (Experience.ExperienceEffect myEffect)//Constructor for CustomClass { Debug.Log ("I'm calling a customClass!");//When the class is created, it should spam the log...right? } } } And it compiles! However, the code does not execute...which makes me understand what you guys were saying about coding "elsewhere". So if I need to explicitly call the methods later, I am thinking it would be best to including a bunch of if statements to check whether or not a Kerbal with that trait is on the craft in OnUpdate (under a class that extends PartModule). Essentially: OnUpdate() { foreach(Kerbal in Craft) { if(Kerbal.Experiencetrait == desiredTrait) { Kerbal.trait.desiredMethod() } } } Would that be advisable? Or am I missing a better/more common way to do it? There seems to be very little supply of mods that alter Kerbal traits...and speaking of, is this a new addition in 1.0/1.1? All the posts I've read seem to say that this is not doable.
  6. @GGumby thank you very much for continuing to work on this. Civilian Population was one of my favorite mods and I was diving into the code to (hopefully) revive it. What did you change to get it to work? By adding the KSP.IO.Util (I think), I was able to get it to compile but hadn't tested it thoroughly. @rabidninjawombat thank you very much for all your work. The above was addressed to @GGumby but I would be very interested in your notes for implementing additional Kerbal roles you mentioned in the previous Civilian Population mod thread. Were you planning on extending the current roles for either crew or tourists or were you planning on keeping the Civilian Population as a resource and manipulating it by using parts (i.e. a payroll part would give a bonus to rent paid when filed with Civilian Population resource)?
  7. I really quite liked this mod, too. I'm not a programmer but it looks line most of the problems are GUI based. I'll see what I can do. I've also got a couple of ideas about changing implementation, mostly to change the population from a resource to actual Kerbals...right now, I'm thinking to keep it simple and make them "tourists". This (I hope) will make integration with life support and other easier. In any event, it'll take a while for me so wrap my head around working with KSP's API. Right now, I've only got a rudimentary IO box working. Also, if anyone has any experience modifying traits, I'd love to heat how is done (I want to add that feature at a later time, after basic functionality is restored).
  8. Hello all! I'm currently working on a mod similar to RabidNinjaWombat's Civilian Population. In his mod, he used civilians as a resource, similar to liquid rocket fuel, mono prop. I believe that was because originally there were no tourists and that was his workaround. However, now we have different classes of Kerbals (crew/tourist). Ideally, my class would be uncontrollable directly by the player (similar to a tourist), but would have attributes that I could modify (such as being a geologist, or accountant) which would be able to interact with parts of the game (mining speed and income over time, respectively). In addition, it would not spawn naturally, but only if the player chooses to spawn it within the station. Though if it is impossible to do otherwise, I would be OK with allowing them to spawn in the roster. Looking through @rabidninjawombat's code, I noticed that ProtoCrewMember.KerbalType assigns the type of Kerbal as crew when the Kerbal is generated . However, since it is an enum, I don't believe it can be modified at runtime. Is that correct? Alternatively, I noticed in [KSP Path]/GameData/Squad/Experience, there is Traits.cfg which I believe belongs to ProtoCrewMember.KerbalType.Crew (again, from @rabidninjawombat's code). This looks like it stores the different types of Kerbal crews (Scientist/Engineer/Pilot) as well as the different effects. However, I cannot find details about this in the API documentation. Is the Scientist/Pilot/Engineer also an enum and therefore unable to be modified? Or is there a class that is called at some point that looks at all of the classes available? Or would I be better served in keeping the civilian/contractor Kerbals as a resource and converting them through that?
  9. @AliceTheGorgon I think I see what happened and it was the same problem you were having: I was trying to create a portable library. I changed it to a .NET library under Other when creating a new solution (ctrl+shift+n). Thank you very much for your help and patience. Here is a brief recap in case anyone in the future should find this thread: 1) Do NOT create a portable library. Instead, under "Other", select "Library". 2) Under Edit -> Preferences -> Project -> .NET Runtimes, I am not sure why, but Mono 4.2.3 needs to be selected as the .NET runtime (see picture 2). I know .NET 3.5 is not supported by Mono 4.2.3 but if I select Mono 3.12.1, I receive a compile error (Message: "Build failed. Unexpected binary element: 0"). Using Mono 4.2.3, I can compile and KSP reads it. 3) Under Project -> [Project_Name] Option -> Build -> General, select Target Framework to Mono / .NET 3.5. Again, the version of Mono I selected should not work but for whatever reason, it does. I just confirmed that it works with the code at the end of this post (which previously gave an error when run; see the preceding posts). using System; using UnityEngine; using KSP; namespace GUITest { public class GUITest : PartModule { public override void OnUpdate () { int myInt = ; string myString; myString = myInt.ToString (); Debug.Log(myString); } } }
  10. @AliceTheGorgon I think I may have originally downloaded the wrong mono file initially; it was loading as mono 4.5 for whatever reason, despite the file name being 3.12.1. I've since tried with a fresh 3.12.1 and it looks like it is now correct. I unzipped the tarball manually (right click -> Extract here). I changed the active directory to the one just created by extracting the tarball. Then I ran: ./configure --prefix=/opt/mono make sudo make install I am able to load it in "Edit" -> "Preferences" -> "Projects" -> ".NET Runtimes" However, the current Mono version does not change. Further, when I attempt to change "Project" -> "<project name> Options" -> "Build" -> "General" -> "Target Framework" to .NET 3.5, I am only presented with an option for .NET 4.5. Here are a couple of images of what I am seeing. You are talking about these menus, correct? Did you overwrite Mono for your entire system or make a parallel install? If you overwrote it for your whole system, do you see any adverse affacts (I may do this as well, then)?
  11. @AliceTheGorgon Thank you very much for the heads up. You likely saved me some headache. I'm recompiling it again. Did you download anything besides mono-3.12.1.tar.bz? That is, did you have to download mono-tools, gtk-sharp, etc... from the Parallel Installation instructions?
  12. @AliceTheGorgon Now that I'm home, I can go a little more in depth. I got Mono tarball from here and I'm currently following the instructions on how to compile Mono on Linux. At the bottom of the page is the Parallel Mono Environments instructions. I will be trying them after the installation finishes. Did you have any luck with your install?
  13. @AliceTheGorgon I got some help from the KSPModders IRC on the general process. I have not been able to test it yet but from what I understand, it should go something like this: 1) Install Mono Develop (which you have done) 2) Download the proper version of Mono (I believe 3.12.1 was suggested) as a tarball 3) Compile it 4) go to Preferences in MonoDevelop, under .NET Framework or something similar, choose recently compiled file
  14. All right, I am thoroughly perplexed. I'm trying to print the number of crew (an integer) to make sure I am using the correct format (the commented-out portion). However, I believe I need to first convert it to a string. I had thought all integer objects had a method (ToString()) which converted them to a string but I'm not so sure now. Per this website, it looks like ToString() should be in the System namespace. Is this correct? When I try to convert the integer to a string, I get this error message in ksp.log (as well as the debug screen): [EXC 21:57:19.572] FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Has anyone here seen anything similar? Am I doing something wrong with my code: using System; using UnityEngine; using KSP; namespace GUITest { public class GUITest : PartModule {public override void OnUpdate() { /*if (FlightGlobals.ActiveVessel.loaded == true) { string numCrew = FlightGlobals.ActiveVessel.GetCrewCount ().ToString();//update string with crew info? print ("[MyMod] calculating crew"); } else { print("[MyMod] not calculating crew"); */ int myInt = 6;//test case; use integer string myString; myString = myInt.ToString ();//ToString() should be in namespace System, right? Exception/Error in log from this. print (myString);//Does not execute } } }
  15. Thank you so much @Padishar! That makes much more sense. I didn't realize its variables were initialized at 0 when the object is created. Again, thank you!
  16. @Padishar I'm afraid I am still new to the language of C# (and object-oriented programming in general). If I understand you, OnGUI and OnWindow are methods that are called by another class and (at least for OnGUI) get called periodically by the game, similar to OnStart. They should be treated as methods I can use to call methods I create (similar to that of OnStart in my code above). Is that correct? I tested with taking out OnStart and it is working better. But now I have a few other questions. 1) By removing the OnStart method above (because it was not necessary for this), how does the label from OnWindow know to associate with the window created by OnGUI? Before, I had thought it was because they both shared the same window ID (10). But with that portion of code taken out, I can't see anything in my code to associate the two. Is OnWindow called by OnGUI? But again, how does OnGUI know to call my additions to OnWindow? 2) In my code, _windowPosition is called and defined. However, it is used in its own definition. Why does this not generate an error? In my mind, it should be similar to this: y = 10 x = y + x print(x) What is x's value? It can't be known because x is never defined a value. Note that I mean the above in the C# sense of assigning value, not the equivalence operator. For reference, my new code (which appears to work correctly): using System; using UnityEngine; namespace GUITest { public class GUITest : PartModule { public Rect _windowPosition = new Rect(); public void OnGUI(){//THis method creates a blank rectangle...I think if (this.vessel == FlightGlobals.ActiveVessel && HighLogic.LoadedScene == GameScenes.FLIGHT) { _windowPosition = GUILayout.Window (10, _windowPosition, OnWindow, "This is a Title!"); print ("OnGUI Executed!");//Spams log if successful } //Concern:_windowPosition is never defined and yet is used to define _windowPosition. WHY is this not an error? else print ("[ThisMod is aborting OnGUI!]");//Spams log if unsuccessful } //Concern: How does OnWindow associate with window above? public void OnWindow(int windowId){//This mod populates the blank rectangle...I think GUILayout.BeginHorizontal (GUILayout.Width (250f)); GUILayout.Label("This is a label!"); GUILayout.EndHorizontal (); GUI.DragWindow ();//Makes the rectangle drag-able? } } }
  17. Hello everyone! I'm running into some problems creating a simple box with some text that I can move around. Or rather, I'm having a problem *not* creating a box I can move around. My goal is to have a small box that appears *only* during the flight scene (which I believe is after I press the spacebar on the launch pad). I have my class tied to a part per a tutorial I found on the wiki (i.e. module name is the same as my class name. However, my dragable box is appearing as soon as the part is loaded in the editor despite the if condition on line 12: if (HighLogic.LoadedScene == GameScenes.FLIGHT) From the KSP.log file, I'm seeing a lot of [ThisMod is aborting OnStart!] which means that the OnGUI method should not be executing. And yet, it is creating a small box. My code is below: using System; using UnityEngine; namespace GUITest { public class GUITest : PartModule { public Rect _windowPosition = new Rect(); public override void OnStart(StartState state){//Should initialize when scene changes if (HighLogic.LoadedScene == GameScenes.FLIGHT) {//Make sure not in editor (aka in flight scene) OnGUI ();//Calls method to create blank rectangle...but how big is the rectangle? print ("Starting Rectangle!"); OnWindow(10); } else print ("[ThisMod is aborting OnStart!]");//Print to log in case above doesn't execute } private void OnGUI(){//THis method creates a blank rectangle...I think if (this.vessel == FlightGlobals.ActiveVessel) _windowPosition = GUILayout.Window (10, _windowPosition, OnWindow, "This is a Title!"); print ("OnGUI Executed!"); //Concern:_windowPosition is never defined and yet is used to define _windowPosition. WHY is this not an error? else print ("[ThisMod is aborting OnGUI!]");//Print something if above doesn't work } private void OnWindow(int windowId){//This mod populates the blank rectangle...I think GUILayout.BeginHorizontal (GUILayout.Width (250f)); //GUILayout.Label ("MyState: "+currState); GUILayout.Label("This is a label!"); GUILayout.EndHorizontal (); GUI.DragWindow ();//Makes the rectangle drag-able? } } } Does anyone have any idea why this would be happening? I'm completely in the black.
  18. I had this same issue when I installed the game on Ubuntu 14.04. What fixed it for me: Go into settings -> Grphics. There will be an option for Edge Highlighting (PPFX). Try unchecking that and going back into the VAB.
  19. Issue: When browsing the craft in either the VAB or in flight with the right mouse button (click + hold + move), the mouse cursor will move to the center of the screen (even if I was on the right and moving towards the right edge) and will keep trying to move back when I move the mouse away. There is about a 10 cm (roughly 0.5 in) diameter circle that I can move the mouse before the game moves it back. If there is a menu in this area (such as from a mod), the game is unrecoverable because I cannot move the mouse to close the window and/or right click on the background (which temporarily removes this issue until I right click to rotate again). EDIT: Problem resolved. This issue was caused by the double click to view feature introduced in 1.0.5. Disabling the feature allows the game to play as normal. A second issue that may or may not be related is that KSP is reporting the version as 1.0.5.0 but when I look at the "build id" line in the BuildID file, it reports 1.0.5.01028. I am using the KSP.x86_64 program in the Steam KSP folder and the auto-created desktop icon. Here is an imgur album that shows what I mean: http://imgur.com/a/Bqwps EDIT: It looks like the version numbering is a well-known issue with Ubuntu installations and the 1.0.5.01028 in the BuildID is correct. Relevant Information Computer: Aspire V3-572P KSP through: Steam KSP Version: 1.0.5.01028 (see above), fresh install through Steam, no mods. I've also deleted/reinstalled KSP to confirm it's not a local file issue. Mouse Type: LogitechM570 wireless trackball and touchpad that came with laptop (confirmed the issue on both) Operating System: Ubuntu 14.04 LTS, 64-bit Recreating the Issue Go into the VAB, place a root part. Then rotate around it using the right mouse button (click + hold + drag). Within ~ 10 seconds, you should see the mouse brought to the center of the screen. It will be kept there until you right click in the center of the screen. Alternatively, install Precise Node and put a craft into orbit. Create a new maneuver node and right click any of the buttons. Within ~5 clicks, the mouse will be brought to the center of the screen and held there until you right click in the center of the screen. This issue was not present for me in 1.0.4 with the same computer (and same install). I don't know if it was present in 1.0.5.1024 or not because I did not play the game until after 1.0.5.1028 was released. If there's anything else that would be helpful, let me know!
  20. I'm just setting up a Minmus base and already have more than enough science to unlock the Duna-capable antenna (if not the farside-capable, definitely the near-side one). I think I did about 3 or 4 single biome landings in each with maybe a goo or science lab or just EVA experiments. If I hadn't dawdled, I could have met the first Duna transfer window.
  21. @FancyMouse Wow I can't believe I had missed those lines. Thank you! @Polnoch I am using the CTT in my current save and everything has been satisfactory in terms of node placement as long as you go to the Mun before Minmus.
  22. I'm trying to mod some station components to act like the Remote Guidance Unit in your mod (i.e. have over X kerbals on board, reset signal lag times, and act as a command center). However, I can't find where the RGU information is in the mod. According to the wiki, it should be called ProbeStackLarge in the game data files. But in the /GameData/RemoteTech/RemoteTech_Squad_Probes.cfg file, the RGU doesn't have anything that looks like it similar to other probes. Is the information stored somewhere I overlooked, or is it not possible to add this functionality without writing a new .dll file?
  23. I had similar problems when I moved Minmus/Cinmus to Kerbin. I figured it was something I had messed up. But it sounds like others are running into the same problem. A potential workaround to "explore X" is to take crew reports. I believe that still worked.
  24. With specialists, how easily do you want bases to be self-sufficient without Kerbals coming in to bring supplies? Put another way, do you want farmers and agricultural engineers to be necessary for self-sufficiency and one of the only specialties to produce more than they consume? Some examples of what I mean: If you want them to be necessary, I would make some careers into a tree of specialization. A farmer/botanist is able to produce more food than other civilians while in the farms. After a while he has gained enough hands-on experience and can specialize. let's say there are two jobs that he can do: Either he can focus on sanitation engineering (mulch/waste) or he can focus on the food chain engineering (food/supplies), giving a larger bonus to one or the other at the cost of specializing in one. So if you had two farmer that could specialize, instead of giving a small bonus to both, one farmer could specialize in a field giving a 10% increase in food growth while the other specializes in a field giving a 10% reduction in waste production for a cumulative bonus higher than if neither had specialized. Then on the other side of the production chain, a recruiter could start off managing Kerbals for a small deduction of recruitment cost. After a while, he can go into being a manager and retain the bonus of recruiter increase the amount of civilians that can be kept on the station (e.g. that broom closet would make a great 1-bedroom studio with the right attitude...that wall can be moved a few feet back to meet code). Or he could go into advertisement and increase the rate civilians come to your stations. But the larger responsibility comes at a cost: He's taken up binge eating and consumes about 1.25x what a base civilian does (requiring more ag). Just some thoughts. It really depends what your vision is and how much you want to implement.
  25. That's great to hear! I'm looking forward to the changes you've been looking forward to. Is this true? From the first page, it mentions needing a minimum of 50. I mean the small house works great if it's only 20. I can manage 3-5 (3xpopulation, 1xwith supplies, 1xKerbals/lander ) ships coming into Duna orbit pretty easily. But 6-10 gets unwieldy really fast.
×
×
  • Create New...