Jump to content

Module and Resource example


Recommended Posts

Trying to work through the mechanics of the new plugin system. I built something resembling Mu\'s example of a generic rocket module, and resource tank. The code to make the tank display like an actual FuelTank isn\'t working yet, but it does appear to be actually doing what it\'s supposed to. This is built as 2 'Part' Parts, one as a dual chamber LOX/LH2 tank, the other as a LOX/LH2 rocket, both are using C7\'s structural fuselage as a base.

I\'m posting this here in case anyone is having problems just getting the new system setup into something that works, and want\'s a concrete example to examine.

http://dl.dropbox.com/u/74137297/KISModuleDemoV0.zip

There\'s also an OOO spreadsheet I made for calculating all the fiddly conversions. May or may not be horribly inaccurate.

-24May12-

Newer code with tons of debug.logs for your parsing pleasure. Think the fuel tank at least works as it, but can\'t test it without the engine running properly.

http://dl.dropbox.com/u/74137297/KFuelTank.cs

http://dl.dropbox.com/u/74137297/KPropulsionBase.cs

-11Jun12-

I accidentally fed the code after midnight, then spilled water on it, and it\'s grown into a horde of angry gremlins. This is in no way suitable for public consumption yet, but I did manage to get several more things working in game, and it\'s actually flyable atm.

screenshot173d.jpg

https://dl.dropbox.com/u/74137297/KISModuleDemoV2.zip

Link to comment
Share on other sites

Just a quick question, so far I\'ve only glanced over the example:

Why the conversion from kg to kerbogram? Shouldn\'t mass be the same everywhere, and only the weight force require adjustment?

Or am I missing something obvious?

Link to comment
Share on other sites

I\'m actually using real Earth values in everything still.

The conversion was just from the density of 6:1 LOX:LH2 to the density of 'fuel' in the default KSP rocket tanks. I was worried that the 'amount' values in my fuel tanks were so small(the net thrust per tank is equal assuming you\'re using this engine/tank, and LiquidEngine1/FuelTank), and the fuel consumption in the engines is also tiny.

The real problem with conversions is that Kerbin g is almost identical to Earth g, which would suggest a 1:1 ratio, but the actual planet, and all the rocket parts are smaller than Earth counterparts. And the metrics used to measure non-distance stuff is also out of scale.

In other words, using the kg:KG conversion factor should give you something more like the 500 'amount' of fuel in a tank, instead of 4.45 total in my tank. Also should bring the engine consumption from 0.0713/s closer to LiquidEngine\'s 8/s. The tiny values from direct conversion don\'t seem to cause noticeable problems yet, so I just left the KerboGram/KerboLiter in to make it clear what\'s an earth measurement, and what\'s a KSP measure.

Link to comment
Share on other sites

Been working on this still. Wanted to let anyone who was dissecting this know that it looks like the engine is loading it\'s required propellants correctly when the part cfg file is parsed, but then somehow loses that data by the time the ship actually gets to the runway. So while the engine appeared to be working, it wasn\'t actually burning (or even checking) any of the resources it was supposed to.

I also managed to make the stack icon update to a fueltank icon if it\'s left at mysterybox, and I think the only thing stopping the fuel bars showing now is that the fuel level is never actually adjusted by the engines.

I\'ll re-upload it once I get the propellant persistence problem sorted out.

Link to comment
Share on other sites

In other words, using the kg:KG conversion factor should give you something more like the 500 'amount' of fuel in a tank, instead of 4.45 total in my tank. Also should bring the engine consumption from 0.0713/s closer to LiquidEngine\'s 8/s. The tiny values from direct conversion don\'t seem to cause noticeable problems yet, so I just left the KerboGram/KerboLiter in to make it clear what\'s an earth measurement, and what\'s a KSP measure.

Thanks for explaining, I see now what you are doing there and why.

Link to comment
Share on other sites

Hi, following your example, I tried to build a very simple part, an advanced command pod that also has the ASAS and MechJeb functionalities.

Unfortunately it did not work :( the part is loaded, but it is not displayed among command pods, it is displayed as a common part and has no function (no MechJeb, and, it seems, no ASAS).

What did I do wrong? Is what I wanted to do possible at all?

(cfg file follows)


// --- general parameters ---
name = advancedmk1pod
module = Part
author = Maraz | Mrbrownce

// --- asset parameters ---
mesh = mk1pod.DAE
scale = 0.1
texture = mk1podtexture.png
specPower = 0.1
rimFalloff = 3
alphaCutoff = 0.0

// --- node definitions ---
// definition format is Position X, Position Y, Position Z, Up X, Up Y, Up Z
node_stack_bottom = 0.0, -3.02662, 0.0, 0.0, 1.0, 0.0, 1
node_stack_top = 0.0, 3.93121, 0.0, 0.0, 1.0, 0.0, 0


// --- editor parameters ---
cost = 1600
category = 1
subcategory = 0
title = Advenced Command Pod Mk1
manufacturer = Kerlington Model Rockets and Paper Products Inc.
description = Originally built as a placeholder for a demonstration mock-up of a rocket, the Mk1 Command Pod was heralded as a far safer and more reliable option than it\'s predecessors by rocket scientists throughout the world. It is now commonly seen in active service.

// attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision
attachRules = 1,0,1,0,0

// --- standard part parameters ---
mass = 1
dragModelType = default
maximum_drag = 0.2
minimum_drag = 0.15
angularDrag = 2
crashTolerance = 14
maxTemp = 3400

MODULE
{
name = CommandPod
rotPower = 5
linPower = 10

Kp = 1.0
Kd = 1.0
}

MODULE
{
name = AdvSASModule

Ki = 0.5
Kp = 1.0
Kd = 1.5
}

MODULE
{
name = MuMechJeb

}

// ----- DO NOT EDIT BELOW THIS POINT ------

Maraz

Link to comment
Share on other sites

If you want it to show up as in the 'pick a pod' list, you need to set it as:


// --- general parameters ---
name = advancedmk1pod
module = CommandPod
author = Maraz | Mrbrownce

AFAIK, there are no 'modularized' versions of the CommandPod, ASAS, or MechJeb as of yet, so no you can\'t do that so far without writing your own versions of them.

The problem is that they haven\'t been updated to the new PartModule system yet, the classes CommandPod, AdvSASModule, MuMechJeb are still setup as being their own parts, not to work as assignable PartModule(s).

Once we get versions of them that are set up as PartModules, that should work like you had it.

Link to comment
Share on other sites

I found

ModuleAerodynamicLift

ModuleAnimateHeat

ModuleAnimatorLandingGear

ModuleCommand

ModuleEngineRocketLiquid

ModuleResource

and ModuleResourceIntake

in the object explorer. They seem to be the only stock part modules for now. Whould suffice for integrated planes ;D

I also found something called StackIcon.partModule. What could that be for?

Link to comment
Share on other sites

I believe those Module classes are just the examples from Mu\'s thread.

StackIcon.partModule is very interesting, have to take a look when I get through fixing whatever is fubar with my joint fixer plugin. I\'m thinking it might possibly be an extension to the normal stack icons, as they\'re generally tied to the Part, not the PartModule. I had to cheat to get my fuel tank part to show a fuel tank icon.

Link to comment
Share on other sites

If you want it to show up as in the 'pick a pod' list, you need to set it as:


// --- general parameters ---
name = advancedmk1pod
module = CommandPod
author = Maraz | Mrbrownce

AFAIK, there are no 'modularized' versions of the CommandPod, ASAS, or MechJeb as of yet, so no you can\'t do that so far without writing your own versions of them.

The problem is that they haven\'t been updated to the new PartModule system yet, the classes CommandPod, AdvSASModule, MuMechJeb are still setup as being their own parts, not to work as assignable PartModule(s).

Once we get versions of them that are set up as PartModules, that should work like you had it.

Thanks for clarification. So I\'ll have to wait....

Maraz

Link to comment
Share on other sites

  • 2 weeks later...

Mu say: 'So you can\'t use constructors on classes derived from MonoBehaviour (Part, PartModule, etc). To do your constructor stuff in a PartModule you need to the override OnAwake method.'

Which explains quite a lot of the bugs I\'ve been having. I think I have the C# thing mostly nailed down, but learning Unity is still troublesome.

Not going to update my code here right now, as I\'m almost done with a larger system this is a prototype for, but in short:

Do Not

-use class constructors for Unity stuff

Do

-use OnAwake to do constructor stuff

Also Do from Mu

public string classdata = '';

As in provide default values for stuff that defaults to null, but don\'t do it in a constructor. Also, check for null in OnAwake, before just assigning new:


if(DumDumList == null)
{
DumDumList = new List<DumDums>();
}
//instead of
DumDumList = new List<DumDums>();

EDIT: Also, if you open a part.cfg that uses ConfigNode stuff in NotePad++, and set the Language to Batch, it handles the structure very well.

Link to comment
Share on other sites

  • 2 weeks later...

Added link to more functional version. Really needs cleaning up, but lots of low level stuff is working now. It also pulls fuel properly, and evenly, though I couldn\'t get the actual KSP resource request system to work right, and made my own.

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