Jump to content

is there a custom part module crash course?


Recommended Posts

what i want to do is have intakes that produce resources based on the components of a planet's atmosphere (perhaps even hydrosphere), rather than the binary oxygen/no oxygen option the intakes give us. i think it will be in the form of a resource converter that will take an agnostic intake resource output from a stock intake module, and based on some planet specific look up tables it will output resources in the correct proportions. will probably use float curves to indicate the proportion of a resource vs altitude with respect to sea level, one for each resource present in that atmosphere. 

pretty straight forward stuff, i only need a couple pieces of information from the game, the rest loaded from a cfg. but i have no clue where to start. if there was an example of a very simple part module or a tutorial to make one that would help a lot. 

Edited by Nuke
Link to comment
Share on other sites

yea i know how to program more or less, and ive got my hello world dll to compile, which i guess means i set up my ide correctly. ive never used c# but i do know c/++ pretty well and i skimmed the wikipedia page on the language. i usually work with low level embedded devices, like i just finished writing linux drivers for an i2c controller i built for my raspi. 

what i dont have is a working knowledge of unity (aside from the part tools) or the ksp way of doing things. ive read through the getting started thread. right now im trying to get my head around cfg loading. not quite sure where to put the code for that. 

Edited by Nuke
Link to comment
Share on other sites

1 hour ago, Nuke said:

yea i know how to program more or less, and ive got my hello world dll to compile, which i guess means i set up my ide correctly. ive never used c# but i do know c/++ pretty well and i skimmed the wikipedia page on the language. i usually work with low level embedded devices, like i just finished writing linux drivers for an i2c controller i built for my raspi. 

what i dont have is a working knowledge of unity (aside from the part tools) or the ksp way of doing things. ive read through the getting started thread. right now im trying to get my head around cfg loading. not quite sure where to put the code for that. 

you might get some ideas from the mod being prepped for release this week: ODFC (on demand fuel cells).

As long as you don't have to do windows or things like that (or even toolbar buttons) - just keep everything in the PAW - you don't have to really worry (much) about Unity.

 

 

Link to comment
Share on other sites

will check out the repo tomorrow. i kind of want to deal with the problem where intakes having essentially 2 intakes built in so that it will work with both the ducted fan and the the jet engine. of course being able to skim jool for fuel is nice too. plan is to use mm to replace all the intake resources with an intermediate that my module will convert, and it will split it into its fractions. but i figure if i make it spew out intake air when im on an oxygen atmosphere it will maintain stock functionality. of course if another mod wanted to go nuts with it, you might have a dozen resources within an atmosphere or hydrosphere, even layers of resources, say an ozone layer, that you can skim for oxidizer. anyway i only came up with the idea a few hours ago. but its late and i need sleep.

Edited by Nuke
Link to comment
Share on other sites

10 hours ago, Nuke said:

yea i know how to program more or less, and ive got my hello world dll to compile, which i guess means i set up my ide correctly.

what i dont have is a working knowledge of unity (aside from the part tools) or the ksp way of doing things.

Cool, the first thing is to inherit from PartModule:

https://kerbalspaceprogram.com/api/class_part_module.html

Iniitialize things in `public override void OnAwake` and `public override void OnStart`.

The part you're attached to can be accessed from the `part` property, likewise with `vessel`.

If you define a `public void Update()` function, the game will call it every UI tick.
If you define a `public void FixedUpdate()` function, the game will call it every physics tick.

Use the KSPField attribute to add values to the Part Action Window:

https://kerbalspaceprogram.com/api/class_k_s_p_field.html

And the KSPEvent attribute to add action buttons to the Part Action Window:

https://kerbalspaceprogram.com/api/class_k_s_p_event.html

Part info can be gotten via `part.partInfo.partConfig.GetNode("MODULE", "name", moduleName)`.

Possibly useful example here:

https://github.com/HebaruSan/SmartTank/blob/master/src/SmartTankPart.cs

Edited by HebaruSan
Link to comment
Share on other sites

last night i was playing around with the cfg loader just trying to get a handle on how it works. im not sure if it would be better just to pull the data out of the node or if it would be better to parse it all in a class hierarchy. here's a sample node off the cfg i cobbled together for testing purposes.

	PLANET
	{
		Name = Laythe
		AtmoComponent
		{
			Type = IntakeAir
			RatioCurve
			{
				key = -10000 0
				key = -1 0
				key = 0 1
				key = 50000 1
			}
		}
		AtmoComponent
		{
			Type = Water
			RatioCurve
			{
				key = -10000 1
				key = -1 1
				key = 0 0
				key = 50000 0
			}
		}
		//ozone layer!
		AtmoComponent
		{
			Type = Oxidizer
			RatioCurve
			{
				key = -10000 0
				key = 40000 0
				key = 50000 1
			}
		}
	}

so were looking at a root class with a couple default settings for the mod and a list of planets, each planet has a list of atmospheric components, and each of those has a float curve associated with it (i can just use the built in class for that). il just focus on getting it to work first and then figure out where to put it. 

1 hour ago, HebaruSan said:

Cool, the first thing is to inherit from PartModule:

https://kerbalspaceprogram.com/api/class_part_module.html

Iniitialize things in `public override void OnAwake` and `public override void OnStart`.

The part you're attached to can be accessed from the `part` property, likewise with `vessel`.

If you define a `public void Update()` function, the game will call it every UI tick.
If you define a `public void FixedUpdate()` function, the game will call it every physics tick.

Use the KSPField attribute to add values to the Part Action Window:

https://kerbalspaceprogram.com/api/class_k_s_p_field.html

And the KSPEvent attribute to add action buttons to the Part Action Window:

https://kerbalspaceprogram.com/api/class_k_s_p_event.html

Part info can be gotten via `part.partInfo.partConfig.GetNode("MODULE", "name", moduleName)`.

Possibly useful example here:

https://github.com/HebaruSan/SmartTank/blob/master/src/SmartTankPart.cs

lots of useful info there, thanks.

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