Jump to content

How can I find the amount of 'lab data points' an experiment will produce?


Recommended Posts

Ah ModuleScienceLab, how you torment me so.

I'd like to get the 'lab data points' for a particular ScienceData, but neither the ScienceData nor the ModuleScienceLab will provide it to me.

[LIST]
[*]KSP 1.0.4
[*]ship is a lab in orbit of Kerbin
[*]1 scientist in the lab
[*]we have a low-space goo Science Data
[*]that data is in the Goo, and [I]has not[/I] been copied to the lab
[*]there are no resource concerns: adequate power, lab has room to accept data, etc.
[/LIST]

The data is worth 20 pts of science, and 25 pts of 'lab copy data'. I'd like to programmatically get that 25.
I checked the ScienceData.labValue (this seems like a relatively new member), but it's zero.
I checked ModuleScienceLab.GetBoostForData(ScienceData d), but it's also zero.

How can I retrieve the lab data points for a Science Data & Lab?

PS - paging xEvilReeperx Edited by SixHourDays
Link to comment
Share on other sites

You know, funny thing is that I haven't really messed with the mobile lab since before 1.0 and didn't even notice they changed things around on me. I don't know why those methods were left in, they seem to be returning placeholder values now

This should do the trick (written for 1.0.5 but should work for 1.0.4):
[code]private static float CalculateLabData(Vessel vessel, ScienceData data)
{
if (vessel == null) throw new ArgumentNullException("vessel");
if (data == null) throw new ArgumentNullException("data");

// note to self: apparently every lab returns same score, so I
// guess it doesn't matter which we use?
//
// ps: the various multipliers are KSPFields so there's a potential for a best
// candidate still if somebody tweaks them. Not going to deal with that now
var lab = vessel.FindPartModulesImplementing<ModuleScienceLab>()
.FirstOrDefault();
var subject = ResearchAndDevelopment.GetSubjectByID(data.subjectID);

if (lab == null || subject == null) return 0f;

var refValue = ResearchAndDevelopment.GetReferenceDataValue(data.dataAmount, subject) * HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier;

return Mathf.Round(GetScienceLabMultiplier(lab, subject) * refValue);
}

private static float GetScienceLabMultiplier(ModuleScienceLab lab, ScienceSubject subject)
{
var multiplier = 1f;

// lab can't process data twice
if (lab.ExperimentData.Any(storedId => storedId == subject.id)) return 0f;

if (lab.vessel.Landed)
multiplier *= 1f + lab.SurfaceBonus;

if (subject.id.Contains(lab.vessel.mainBody.bodyName))
multiplier *= 1f + lab.ContextBonus;

if ((lab.vessel.Landed || lab.vessel.Splashed) &&
ReferenceEquals(FlightGlobals.GetHomeBody(), lab.vessel.mainBody))
multiplier *= lab.homeworldMultiplier; // lack of addition intended

return multiplier;
}[/code]
Let me know if you find a bug in there, it looks eyeball right but I haven't tested it extensively yet
Link to comment
Share on other sites

Thanks so much! I didn't think Squad would make me put this in explicitly...foolish me.

Your code looks about right, except the 'grounded' case should be Landed || Splashed for both if statements.

Also, can I hug you? HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier has been sitting in my code as "float m_hackICantFind = 2f;" for about 3 months now! It feels SOOOO good to know where the blazes that number comes from, finally!

Thanks so much for your help.
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...