Jump to content

Recommended Posts

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? 

Edited by Tralfagar
Editing tags to be more specific
Link to comment
Share on other sites

As a quick test I edited one of the Kerbals in the roster section of the persistent.sfs to have "trait = MissionSpecialist" and added the following block to the end of traits.cfg:

EXPERIENCE_TRAIT
{
	name = MissionSpecialist
	title = Mission Specialist
	desc = Does specialised duties on missions.
	
	EFFECT
	{
		name= RepairSkill
	}
}

When viewed in the astronaut complex after loading the game that crew member showed up as "Mission Specia". The space in the portrait in flight was even more limited displaying just "Mission". So it can be customised but there's a hard limit on the length of name that will display. 

Link to comment
Share on other sites

You can't change the ProtoCrewMember enums for RosterStatus and KerbalType. These are fixed Enums.
so the kerbals can only be Crew, Application, Unowned, Tourist. and they can only be Available, Assigned, Dead or Missing.
You can create your own Experience Traits as you have discovered above, but you will have to code the effects everywhere else that you want them to take effect as anxcon has said.

 

Link to comment
Share on other sites

  • 3 weeks later...

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.

Edited by Tralfagar
Pressed the wrong button initially.
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...