Jump to content

Unknown Object Parameters


Recommended Posts

So I'm working on one of my first mods and it has to do with asteroids. My question is let's say that in the tracking station there is an unknown object (which is just an untracked asteroid). Let's say in my plugin I want to do something with all class b asteroids. How do I find out what class every asteroid in the tracking station is. Sorry if this is a confusing question, I'm a noob at plugins. If you need clarification just ask!

Link to comment
Share on other sites

Because KSP is awesome, there are two values that indicate asteroid size and only one of them is always reliable, but isn't always available. :confused:

When an asteroid is untracked, or hasn't been actually visited (as in, you haven't traveled to within 2.5km of it) you can reliably get the asteroid size based on its Vessel.DiscoveryInfo.Size value. This value is, I think, just an integer from 0-4, 0 is class A, 1 is class B, etc...

The problem is, once a vessel docks to that asteroid it becomes Size = 2, regardless of the original asteroid size class (all regular vessels that you launch are Size = 2). To get the asteroid size at this point you have to look at the asteroid's ModuleAsteroid PartModule, then look at the last character of the prefabBaseURL field; the last character is A, B, C, etc... It's just a string, and it's persistent, so you should be able to access it while the asteroid isn't loaded. The only problem is that the asteroid doesn't have a ModuleAsteroid instance (or it isn't actually loaded) until you visit the asteroid.

Edited by DMagic
Link to comment
Share on other sites

Before you do that you are going to need to get all the asteroids that are currently spawned. I am doing this with

IEnumerable<Vessel> asteroids= FlightGlobals.Vessels.Where(v => v.vesselType == VesselType.SpaceObject);

then you can loop through the asteroids and check the prefabbaseurl

foreach (Vessel asteroid in asteroids)
{

Link to comment
Share on other sites

That will find you all the asteroids.

To get only the ones that are being tracked I think you will have to do something like

asteroid.DiscoveryInfo.HaveKnowledgeAbout(DiscoveryLevels.Name)

experiment with a few different levels unto you get the one you want though

Link to comment
Share on other sites

OK, so like I said before, I'm really new to coding in general. Microsoft Visual Studio is not understanding IEnumerable<Vessel>. Am I missing a reference (I've added Assembly-CSharp.dll and UnityEngine.dll). Please Help!

EDIT: Ok, I added some using System.Collections.Generic to the top and now it recognizes IEnumerable but still not asteroid (in asteroid.vessel.DiscoveryInfo.size.Value) and some other things as well.

Edited by Ulico
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...