Jump to content

[0.20.2] Resource Generation Module (0.28)


Fel

Recommended Posts

Simply put, adds a "ResGen" module to the game that can be attached to any Part to turn it into Resource Generator / Consumer / Converter which can be fully configured in the Part.cfg file.

It "looks ahead" before trying to consume anything and adjusts consumption / generation accordingly.

Don't really know where I'm going with this, have a few ideas (such as adding "Sunlight" as a "Hidden Resource,") but... I think it'll mostly end up being "Theme and Variation" (i.e. ResGenCrewMult, ResGenExponential)

Version 0.1,

Initial Release, Proof of Concept.

Version 0.11

Just a few final source cleanups (and a small memory leak).

Version 0.2

Added "Hidden Resources (extreme alpha)"; made ResGen.Module polymorphic for simplified editing

The "ResGen.Sunlight" does NOT PROPERLY WORK. (The RayCast never returns false) but the interaction between resource / ResGen.Module is what I am documenting.

Version 0.21

Source Cleanup and fixed a really dumb bug

Version 0.22

I now have "ResGen.Sunlight" operating without a large performance hit and somewhat accurately

Hidden Resource system is still fairly weak and it is only using an "on / off" system (or hacking in local variables)

Version 0.23

Finished up most of the Hidden Resource system for now;

Resources will now use the ConfigNode system to store / pass information

Did some theme / variations while I was at it:

Added in "ResGen.PartCrew"

INPUT: returns "PartCrew Count"

OUTPUT: returns "PartCrew Capacity - Count"

Added in "ResGen.VesselCrew"

INPUT: returns "VesselCrew Count"

OUTPUT: returns "VesselCrew Capacity - Count"

Added in "ResGen.AtmosphereHasOxygen"

INPUT: returns "5" if oxygen is in the atmosphere

Added in "ResGen.AtmosphericOxygen"

INPUT: returns "Atmospheric Density" if oxygen is in the atmosphere

Added in "ResGen.Sunlight"

INPUT: returns "5" if the part is visible to the sun.

Added in "ResGen.PlanetWater"

INPUT: returns "5" if the vessel is "Spashed"

Added in "ResGen.GeeForce"

INPUT: returns the geeForce

Added in "ResGen.Explode"

OUTPUT: well, will explode the part unless the inputs prohibit it

Added in "ResGen.OnPlanet"

requires a field "planet = name" in the resource listing.

INPUT: Returns 5 if the code works and you are on said planet.

Added in "ResGenMultVesselCrew":

Resource Generation Module: the rate is multiplied by the total crew

Added in "ResGenDivVesselCrew":

Resource Generation Module: the rate is divided by the total crew

Added in "ResGenMultPartCrew":

Resource Generation Module: the rate is multiplied by the part crew

Added in "ResGenDivPartCrew":

Resource Generation Module: the rate is divided by the total crew

Version 0.24

0.20.2 Compatibility

Merged "ResGen_Example" with "ResGen"

Added in "BADINPUT" and "BADOUTPUT" they replace the "INPUT / OUTPUT" resources when there is not enough "INPUT" resources.

Added in "ResGen.KillVesselCrew"

Added in "ResGen.KillPartCrew"

Added in "ResGen.KillKerbalInVessel"

Added in "ResGen.KillKerbalInPart"

Verison 0.25

Added in "ResGen.Timer"

use "

INPUT {

name = ResGen.Timer

rate = 1

setTime = 5

}"

timer is in seconds

Modified "ResGen.KillKerbalInVessel"

Now has a "setTime"

Modified "ResGen.KillKerbalInPart"

Now has a "setTime"

Version 0.26

Bug fix for timewarp on hidden resources (Previously, the slower you went, the more you got). Hidden Resources with flat rates (sunlight, hasAtmosphere) now return "TimeWarp.CurrentRate (i.e. 50x)"

Version 0.27

Added in "ELSE" node, offering a one way conditional switch if inputs are not met.

Version 0.28

Added in ResGen.Temperature (For what it is worth... which is very little)

Added in GlobalVar

Added in GlobalSet

Added in GlobalIsGreater

Added in GlobalIsLess

Added in LocalVar

Added in LocalSet

Added in LocalIsGreater

Added in LocalIsLess

Includes DLL / Source / Documentation

Download

Edited by Fel
Link to comment
Share on other sites

Me too. Parts to actively gather oxidiser from the air on Kerbin and Laythe. Use tanks of oxidiser (from KSPX mod for example) in life support system. Conversion of water into liquid fuel and oxidiser on Kerbin, Laythe, maybe Eve. If ice can be added as a resource we could mine it on Minmus and Eeloo for lf/oxy combo etc.

Link to comment
Share on other sites

Would it be possible for me to use this plugin in my mod? It would save me a lot of time creating the electrolysis unit I have in mind.

Sure, right now (for 0.2) I've turned ResGen into a polymorphic structure allowing me (or others) to very easily add additional modules.


public class ResGenWithButton : ResGen.Module {
private bool toggle = false;

[KSPEvent(guiActive = true, guiName = "Toggle")]
public void Toggle() {
toggle = !toggle;
}
protected override void initRate(ref double delta) {
if (toggle) delta = 0;
else delta *= rate;
}
protected override void getFRate(ref double delta, ResDat resi) {
delta *= resi.rate;
}
protected override void getRRate(ref double delta, ResDat resi) {
delta /= resi.rate;
}
protected override void stoFRate(ref double delta, ResDat resi) {
delta *= resi.rate;
}
protected override void stoRRate(ref double delta, ResDat resi) {
delta /= resi.rate;
}
}

Documentation:

StoForwardRate

StoReverseRate

I decided that, by thinking 30 steps ahead, there is no reason that you should NEED to "Recharge" at the same rate that you "Drain." The expensive part is the function call, so I figured I might as well add in the additional two.

Additionally, if delta=0 most routines will quit. This can occur naturally (such as having a full tank (OUTPUT) or having an empty tank (INPUT)) so it is exploiting "good programming" to add in an additional feature.

The biggest focus has been getting "Hidden Resources" to work the way I want them to...

I am mirroring KSP's own resource system a bit; and if I get the thing working I'll probably rewrite more of it to more precisely mirror it. (Right now I merged PartResource with PartResourceDefinition and have PartResourceLibrary doing silly things)

I also went and looked up a fair bit on Reflection... I don't exactly understand how KSP manages to ignore namespaces; but Type.GetType() works well enough (and avoids the awful bugs of "Whose Class do I Pick")


namespace ResGen_Example {
public class Sunlight : ResGen.Resource {
public override double amount { get {
bool temp = Physics.Raycast(part.orgPos, Planetarium.fetch.Sun.position);
if (temp) MonoBehaviour.print("ResGen: Sun Hit");
else MonoBehaviour.print("ResGen: Sun Missed");
return (temp) ? 50 : 0; } }
protected override double RequestResource_Out(double demand) {
return 0;
}
protected override double RequestResource_In(double demand) {
return 0;
}
public Sunlight() {}
}}

Documentation:

Everything that PartResourceDefinition has is included, can be "get" publicly, and "set" is protected (so you can do it). They're all over-ridable so (again, 30 steps ahead) things can get really complicated as to how resources are handled.

RequestResource is defined in the base class, and is also over-ridable; but it effectively is just

public virtual double RequestResource(double demand) {

return (demand > 0) ? RequestResource_Out(demand)

: RequestResource_In (demand);

}

*** Although, I might abandon that due to simplicity... I just wanted people to understand that you NEED to account for both ends "OUTPUT and INPUT"

Adds a hidden resource of "ResGen_Example.Sunlight."

I also have this include a monobehaviour and each part has their own ResGen.Resource (Mirror of PartResource) which allows the writer to do Part / Vessel specific calculations... or use "OnUpdate" to do fun stuff....

But the code... is refusing... to call RequestResource :mad:

*Let alone that I have no idea about the Unity API and am probably going to abandon the monobehaviour until I get the core finished... just thinking 30 steps ahead.

*Final Note To Self:

Stop thinking 30 steps ahead... then MISSING what you created at step 1.

Hidden Resources are currently gimped (but operate); what I was doing ignored other potential problems anyways and needs a rewrite.

Edited by Fel
Link to comment
Share on other sites

Extensibility.

The polymorphic structure allows for light task specific Modules. (So technically, I'm not as heavy as ModuleGenerator because I only do what I need to... but I can add in much more.)

Furthermore, the main focus is about "Hidden Resources" which are also designed to be an extremely extensible way of introducing any game variable as a resource. (And it isn't even tied to the DLL which allows anyone to add their own "Hidden Resource", or remove it later on.)

Link to comment
Share on other sites

And... I have no clue what I should do with this now.

Hi, this seems like an awesome mod that I think can have very many potentials for building up an economy in KSP for resources. Ie. producing raw materials, processing them to materials needed for flight (fuel) and materials needed by the various life support mods (eg. mining for materials needed to fill up a hydroponics plant needing the hidden variable sunlight, carbon dioxide and heating/electricity before producing food & oxygen).

What would be missing to make such an economy slightly more complex would be more of your hidden variables, most notably I would like to see hidden variables that can represent useful inputs for mining purposes. Three examples of variables that would be useful for that would be:

1. A noise function that can be used to determine the precense of a given raw material (eg. like for the kethane mod). It should map the crafts current latitude and longitude to an input using perlin noise (or even better, simplex noise - which already is implemented in KSP in the class SimplexNoise, with octaves, persistance and frequency as parameters. I would suggest making these parameters available to the part-making user in order to tweak the frequency and size of the areas that have resources.

2. Hidden variables for ground altitude (eg. altitude below or close to sea level can be used for mining water on water based planets).

3. Hidden variables for closenes to specific parts of a planet. (eg. ice can be mined on Duna when close to the poles).

If you would like to implement something like this for your mod it would be awesome. If not, i wonder if you would mind if I pick apart your code and try to do something similar otherwise? (What license do you give to the code - GPL?)

Link to comment
Share on other sites

Do you have in your plugin or do you know how to kill the Kerbals one by one. or also make the craft uncontrollable? So when they run out of air... Dead.

I'm setting up life support now with this plugin. this would make this plugin so much better.

Link to comment
Share on other sites

This looks awesome! I tried using it for v3.0 of the B9 pack, as I had a use for a smart generator, but even when compiled with the 0.20 references I couldn't get it work.

It would be awesome if you post an updated version that works in 0.20.1 :D

Link to comment
Share on other sites

Okay, I'll see where the problems lie.

/Add in kerbal killing

Successful test on regular resources... so not much was broken.

Added in "BADINPUT" and "BADOUTPUT", triggered when the "INPUT" list cannot supply said inputs (i.e. Oxygen for Lifesupport)

Did a few tests to see if I could do some code improvements.

Fixed a long existing but that I never really noticed because I never tested for it.

I think I need some form of timer to "kill kerbals 1 by 1"

Edited by Fel
Link to comment
Share on other sites

Could this be used to make a compressor for RCS fuel? I know true RCS is not compressed atmospheric gas, but for a VTOL it does not make a lot of sense to carry a finite amount of RCS fuel around when you can quite easily compress it on the spot.

Link to comment
Share on other sites

Could this be used to make a compressor for RCS fuel? I know true RCS is not compressed atmospheric gas, but for a VTOL it does not make a lot of sense to carry a finite amount of RCS fuel around when you can quite easily compress it on the spot.

That's kind of why I'd like to use it.

Currently the B9 3.0 VTOL-RCS uses air and electricity to make B9CompressedAir, and that works fine, but the generator must be manually turned on (most convenient is to attach it to the RCS special action group) and its always drawing IntakeAir and ElectricCharge even when its tank is full.

Fel, the resource is flowMode = NO_FLOW and transfer = NONE, density 0.01, and there's a small (0.1) size tank in each RCS port along with the generator.

Link to comment
Share on other sites

Fel, the resource is flowMode = NO_FLOW and transfer = NONE, density 0.01, and there's a small (0.1) size tank in each RCS port along with the generator.

Oh, I see... I thought you were talking about force transferring resources; which brings up an interesting discussion

*** Was Writing This ***

Okay, so I can walk the vessel at load and verify that the Part Count has not changed (It is fairly simple to check if a part is still on the vessel; so just need to know if you docked or something.)

But actually, this can get complicated.

A) Do I drain from first available or all at once (Probably want a flag for that)

B) If draining all at once, do I drain by percentage, or by value? (Another flag, I guess XD)

C) If draining by value, what do I do about imbalances? (Say that x tank goes empty, should I keep draining or stop)

*** End Writing ***

The more I think about it, you could do some "interesting things" by changing how things get transfered; Let's say you attach the generator to an engine and say "INPUT (Fuel) OUTPUT (Fuel)"; hence overriding the default "RequestResource" and allowing you to change how the fuel is distributed.

Of course, I am making my own grave by suggesting this... the problem isn't finding the resources, it is the algorithms dictating their flow.

Link to comment
Share on other sites

yes a timer code would be good

Timer(Name, 0, 2, 50, 30, 00)

0= first number left to right (H,M,S) 2=number of units to show ((1=50H)(3=50H:30M:00S)(1, 2=30M:00S)) 50=hours 30=minutes 00=seconds

Starttimer(Name) start timer count down

Pausetimer(Name) stop and hold count down

Resettimer(Name) reset count down back to fist settings

Displaytimer(Name, Text) display a small pop-up window or a line in the right click menu (Text= what title you see on the counter)

Alerttimer(Name, 00, 10, 00) Maybe add an alert timer setting to slow down warp speed and flash the color of the displayed timer when time hits 00H:10M:00S

You could set several timers and when the time hits 0 {} the code in the brackets is run. Some timers would not show, they would just run in the back ground and some would be displayed. You could also add one more setting to the timer up/down count. Start count at zero or count down to zero.

When your O2 tanks are empty timer1, timer2, & timer3 starts. When time1 stops kill 1 kerbal when timer2 stops kill 1 kerbal when timer3 stops kill the last kerbal. Only timer3 was displayed.

Link to comment
Share on other sites

A stylistic note on the readme file; I had to dig into the actual .cs file to find the isActive setting.

I was very intrigued by the ResGen.Explode resource. I immediately tried to make a self-destruct device out of it. I see in the code though that the explosion is limited to the individual part. Could this be changed to allow for some calculated blast power? It might be more fun to vaporize my obsolete stations and ships rather than crash them or end their flight. If so I will have a modeler friend collaborate on a new set of "Kerbam! Self Destruct Devices" as an addon part for the spaceport. That is, with your permission to use this nifty plugin for that purpose.

Link to comment
Share on other sites

I used to play with a similar modified part i created back in 18.4 that created Oxidizer and Fuel with Eletrical Energy. I used it in DUNA's ice cape, Vall surface and Close to oceans in Eve and Laythe (yes i know Eve's ocean isn´t water), so it wouldn´t feel as "cheating". It would be nice if the game added a "zone" in planets with explorabe resources like water and methane witch could be converted to H2 and O2 with parts similar as this mod.

Link to comment
Share on other sites

Tried the following (for use with Ioncross), but no resources get transformed. Any ideas?

PART
{
// --- general parameters ---
name = crewSupportHydroponics
module = Part

MODEL
{
model = Squad/Parts/Command/cupola/model
texture = Squad/Parts/Command/cupola/model000
}

// --- node definitions ---
// definition format is Position X, Position Y, Position Z, Up X, Up Y, Up Z
node_stack_bottom = 0.0, -0.4, 0.0, 0.0, 1.0, 0.0, 2
node_stack_top = 0.0, 0.83, 0.0, 0.0, 1.0, 0.0, 1



// --- editor parameters ---
cost = 2000
category = Utility
subcategory = 0
title = Green Thumb Hydroponics Pod
manufacturer = Jebediah Kerman's Junkyard and Spaceship Parts Co.
description = todo
// attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision
attachRules = 1,0,1,1,0

// --- standard part parameters ---
mass = 4.5
dragModelType = default
maximum_drag = 0.40
minimum_drag = 0.40
angularDrag = 4
crashTolerance = 8
maxTemp = 800

vesselType = Base

RESOURCE
{
name = Oxygen
amount = 50
maxAmount = 100
}
RESOURCE
{
name = CarbonDioxide
amount = 50
maxAmount = 100
}
RESOURCE
{
name = Snacks
amount = 0
maxAmount = 30
}
RESOURCE
{
name = ElectricCharge
amount = 10
maxAmount = 10
}

MODULE
{
name = ResGen
update = 1

INPUT
{
name = ResGen.Sunlight
rate = 1
}
INPUT
{
name = CarbonDioxide
rate = .001
OUTPUT
{
name = Oxygen
rate = .001
}
OUTPUT
{
name = Snacks
rate = .0001
}

BADINPUT
{
name = ElectricCharge
rate = .12
}
BADINPUT
{
name = CarbonDioxide
rate = .0001
BADOUTPUT
{
name = Oxygen
rate = .0001
}
BADOUTPUT
{
name = Snacks
rate = .00001
}
}

Link to comment
Share on other sites

MODULE
{
name = ResGen
update = 1

INPUT
{
name = ResGen.Sunlight
rate = 1
}
INPUT
{
name = CarbonDioxide
rate = .001
[B] }[/B]
OUTPUT
{
name = Oxygen
rate = .001
}
OUTPUT
{
name = Snacks
rate = .0001
}

BADINPUT
{
name = ElectricCharge
rate = .12
}
BADINPUT
{
name = CarbonDioxide
rate = .0001
[B] }[/B]
BADOUTPUT
{
name = Oxygen
rate = .0001
}
BADOUTPUT
{
name = Snacks
rate = .00001
}
}

I will say... I am absolutely horrible at keeping documentation, so if I did that, I'm sorry :(

Also, I'll spend some love here; tomorrow (Well, I have some things I should do then...) so if this does turn out to be a bug I'll fix it / try and take care of remaining requests.

Just got caught up in the KerbalEVA Lifesupport that... no one wants :(

*I fixed the only bug I could find here... everything else is just those missing brackets.

***Also, having a bit of trouble spawning a larger explosion, other likely candidate are the "Detonator Classes"... not exactly certain how that will turn out.

Edited by Fel
Link to comment
Share on other sites

I thank you for adding in the kill commands.

One more request. (Unless you can do this already)

if then MODULE.

IF resource "Heat" in this part is < "number" then (you could also have it look for the first crew module, fuel tank, solar panle, or any name = "")

MODULE

{

name = ResGen

update = 1

INPUT

{

name = ElectricCharge

rate = .001

}

OUTPUT

{

name = Heat

rate = .001

}

OUTPUT

{

name = Heat

rate = .0001

}

BADOUTPUT

{

name = Heat

inmodule = CommandPod

Value >= 75.000

}

}

the badoutput looks for resource Heat in the first CommandPod (or any other module type) up the part chain. if it finds one it looks at the value there. if its 75 or grater it stops the ResGen from making any more. I would also like to be able to set a slow drop in that resource. If the commandPod drops temp to low you can't control it anymore, if it stays that low to long Kerbals die, and if it gets to hot it kills Kerbals or blows up the part.

This would be used for making heat generators (or coolant unit) that i could connect inline or on the side and have it feed one resource from its self to another part.

A heater would keep the crew worm

A coolant unit would pull heat out of a generator so the generator doesn't get to hot.

I could set both of the parts to have a heat image just like the rockets. That would be a kool site. Your space station on the dark side of the plaint with this glowing fines on the side of it.

Link to comment
Share on other sites

I've been trying to use this plugin to make a config edited version of a RCS quad that uses ElectricCharge and XenonGas, but I'm having issues getting ResGen to do what I want.

I have a custom resource called "XenonIons" for the RCS quad to use as fuel. Same density as XenonGas, but it's non-transferable like SolidFuel is.

Here's the resource definition code for it:


RESOURCE_DEFINITION
{
name = XenonIons
density = 0.0005
flowMode = NO_FLOW
transfer = NONE
}

The RCS thruster itself works fine, however the ResGen module doesn't refill the thruster's fuel supply.

I can't figure out what's wrong with it, but any help getting it to work is appreciated.

Here's the important section of the edited RCS quad's part.cfg:


MODULE
{
name = ModuleRCS
thrusterTransformName = RCSthruster
thrusterPower = 0.125
resourceName = XenonIons
atmosphereCurve
{
key = 0 3200
key = 1 0
}
}

RESOURCE
{
name = XenonIons
amount = 0.15
maxAmount = 0.15
}

MODULE
{
name = ResGen
INPUT
{
name = ElectricCharge
rate = 7.0
}
INPUT
{
name = XenonGas
rate = 0.032
}
OUTPUT
{
name = XenonIons
rate = 0.032
}
}

Also, just in case someone is wondering, I know that any ship using these will need at least one Xenon tank, battery, and a way to re-charge the battery.

As a matter of fact, I made a little probe specifically to test out these thrusters.

Because it's such a simple craft, I think describing how to build it might have better data compression than posting a .craft file for it, so I'll do that.

My "RCS tester satellite" has an Okto2 probe core with a RTG on the top stack node and a Xenon tank on the lower one, and the Xenon tank has 2 of the small radial batteries and 2 of the RCS quads I'm working on attached to it's sides. The rocket it rides to orbit doesn't make much difference as long as it can get to a 125km circular equatorial orbit, and because the probe should be less than a ton including fuel, it won't take a lot to get it there. I'm using a booster about the same size as the one for the "Z-MAP Satellite" stock craft.

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