Jump to content

More help needed developing space station mod


CiberX15

Recommended Posts

Ok I am developing this mod here: http://kerbalspaceprogram.com/ciber-x-labs-5/

The system works fine as long as there is only one Lab in use at any given time. But because an active lab changes the Experiment.BaseValue all other labs besides the first lab act very strangely. For example if I put Lab A into space and generate 57 research papers it will give me 57 data and 57 science when I hit the deploy experiment button. However, if I put a second lab, Lab B, on the launch pad, Lab B will read 57 data and only +15 science, where it should not be reading anything at all since it has not done any research yet but is reading Lab A’s experiment definition.

Now what I am trying now is only setting the science value of the experiment when the player clicks the deploy button and immediately setting it back once the player has Kept/transmitted/recycled the data. Setting it was easy, I just intercepted the deploy experiment command and set the experiment.basevalue before letting it run the original function. However, I don’t know where to set it back to default. Is there a function that is always called after you close the experiment window (the one with the keep/transmit/recycle buttons on it)? After that window closes is when I need to reset the value. Or perhaps when the player changes focus, to another ship or goes back to the space port, that would actually work better.

Thanks In advance...

...Again 8 P

Code Below


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;



/// <summary>
/// ScienceTrickle
/// By: CiberX15
/// Special Thanks to Fractal_UK whose KSPInterstellar ScienceModule I reverse engineered
/// to figure out how to work the code
/// </summary>

public class ScienceTrickle : ModuleScienceExperiment
{
[KSPField(isPersistant = true, guiActive = false)]
protected double ActiveTime;

[KSPField(isPersistant = true, guiActive = true)]
protected bool IsEnabled;

[KSPField(isPersistant = true, guiActive = false)]
protected double ResearchTime;

[KSPField(isPersistant = true, guiActive = true)]
protected string CurrentPaper;

protected float crew_capacity_ratio;

[KSPField(isPersistant = true, guiActive = false)]
protected double StoredScience;

[KSPField(isPersistant = true, guiActive = true)]
protected double RecordedData;

/// <summary>
/// Called when the part is started by Unity.
/// </summary>
public override void OnStart(StartState state)
{
base.OnStart(state);

// Check our crew
crew_capacity_ratio = ((float)part.protoModuleCrew.Count) / ((float)part.CrewCapacity);
}

//Begin Research Button
[KSPEvent(guiActive = true, guiName = "Begin Research", active = true)]
public void BeginResearch()
{
if (crew_capacity_ratio == 0) { return; }

ActiveTime = Planetarium.GetUniversalTime();
ResearchTime = 0;
StoredScience = 0;
RecordedData = 0;
CurrentPaper = "";
IsEnabled = true;
}

//Stop Research Button
[KSPEvent(guiActive = true, guiName = "Stop Research", active = true)]
public void StopActivity()
{
IsEnabled = false;
}

//Clear Research Button
[KSPEvent(guiActive = true, guiName = "Clear Research", active = true)]
public void ClearResearch()
{
IsEnabled = false;
ResearchTime = 0;
StoredScience = 0;
RecordedData = 0;
CurrentPaper = "";
}

new public void DeployExperiment()
{
print("Begining Deployment Calculations ==================================================");
experiment.baseValue = (float)RecordedData;
base.DeployExperiment();
}
/*
new public void ReviewDataEvent()
{
base.ReviewDataEvent();
print("ORANGE JUICE==============================================================");
}

new public void ResetExperiment()
{
base.ResetExperiment();
experiment.baseValue = 1;
ClearResearch();
print("Finished Experiment Reset =================================================");
}

new public void ResetExperimentExternal()
{
base.ResetExperimentExternal();
experiment.baseValue = 1;
ClearResearch();
print("Finished Experiment Reset =================================================");
}*/

//Stop Research Button
[KSPEvent(guiActive = true, guiName = "Debug", active = true)]
public void DebugThing()
{
print ("ResearchTime " + ResearchTime);
print ("CurrentPaper " + CurrentPaper);
print ("StoredScience " + StoredScience);
print ("RecordedData " + RecordedData);
print ("Experemrnt BaseValue" + base.experiment.baseValue);
print ("Experemrnt ScienceCap" + base.experiment.scienceCap);
print ("Experemrnt dataScale" + base.experiment.dataScale);
}

public void CheckFindings()
{
//crew mod
float CrewMod = 0;

//calculate crew contributions
foreach (ProtoCrewMember proto_crew_member in part.protoModuleCrew)
{
CrewMod += 1 - proto_crew_member.stupidity;
}

//add collected science
StoredScience += CrewMod * 4;

RecordedData = Mathf.Round((float)StoredScience);
}

//Always Update
public override void OnUpdate()
{
//if the modual is suposed to be making science!
if(IsEnabled)
{
float ResourceDraw = part.protoModuleCrew.Count;
if(ResourceDraw > 0 && part.RequestResource("ElectricCharge", ResourceDraw * 0.25f) >= ResourceDraw * 0.25f)
{
ResearchTime = Planetarium.GetUniversalTime() - ActiveTime;
float Percent = (float)(ResearchTime / 86400) * 100;
CurrentPaper = 0.01 * Math.Round(Percent * 100) + "%";

if(ResearchTime >= 86400)
{
int PapersCompleated = (int)(ResearchTime / 86400);
print ("Papers Compleated = " + PapersCompleated);
for(int i = 0; i < PapersCompleated;)
{
print (i);
if(part.RequestResource("Snacks", ResourceDraw) >= ResourceDraw)
{
CheckFindings();
}
else
{
//shutdown if out of snacks
IsEnabled = false;
ResearchTime = 0;
CurrentPaper = "";
print ("Not enough snacks, shutting down");
}
i++;
}
ResearchTime = 0;
ActiveTime = (float)Planetarium.GetUniversalTime();
}
}
else
{
//shutdown if out of power
IsEnabled = false;
print ("Not enough power, shutting down");
}
}

base.OnUpdate();
}


//In Game Update
public override void OnFixedUpdate()
{
base.OnUpdate();
}
}

Link to comment
Share on other sites

Welp, I figured out that I could reset the Experiment.BaseValue on start. Since research papers count is separate from that players still would get the science because the BaseValue is set when the player hits the deploy button. However, this revealed another problem that I though was part of this one. When the experiment is run a second time it has a diminishing return. so even though the experiments can now be calculated independently, they will still yield unpredictable results when used a second time, or on other ships.

So, any idea how I could make the labs generate unique experiment ID's each time they run?

Link to comment
Share on other sites

  • 2 weeks later...

I tried this yesterday. Works very well. I dunno why the thread dont have more replies. I see a lot of ppl using the components(see the kerbal reinforcement thread there is one craft there that has it) there is defidently interest in this mod and the idea in general. One tip for ciber. Rename your thread to [0.23]ciber x labs[plugin version][latest update] it will be much easier to find as its here most ppl look for mods. The models are a little silly but they are a work in progress so no issues there they look better than a lot of others. Keep up the good work

Link to comment
Share on other sites

Not sure what I'm doing wrong with this plugin; I launched a station into orbit with one of the science modules, an extra snack module, a cupola on the top (base part for C&C), a mechjeb module, a ton of solar panels.. etc. I right click the science module and click 'begin research' and nothing happens. The IsEnabled stays false, and.. none of the buttons do *anything*. Did I miss something obvious? All of the other mods/etc that I have work fine. Using 0.23 with FAR, MechJeb2, and KAS.

Link to comment
Share on other sites

It's interesting the whole operation somehow not being specific to a single instance of a part.

Have you tried specifically designating the class as a part module:

namespace DavonSupplyMod
{
public class DavonRestrictedResourceSupplyModule : PartModule
{

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...