Biotronic / TweakScale

Forked from Gaius Goodspeed's Goodspeed Aerospace Part & TweakScale plugin
30 stars 58 forks source link

Cost bug with empty cheap tanks #7

Closed abienvenu closed 10 years ago

abienvenu commented 10 years ago

The cost calculation in TweakScale v1.37 does not work fine if :

Here is an example of a LiquidFuel costing 400 empty. It is expected to cost 1200 once full (in 2.5m scale). Actually, in the VAB, it will cost 0 empty, and 800 once full.

PART { name = MyTestEmptyCheapTank module = Part author = Abi

mesh = MyTestTank.mu rescaleFactor = 1

node_stack_top = 0.0, 1.875, 0.0, 0.0, 1.0, 0.0, 2 node_stack_bottom = 0.0, -1.875, 0.0, 0.0, 1.0, 0.0, 2 node_attach = 1.25, 0.0, 0.0, 1.0, 0.0, 0.0, 1

TechRequired = heavyRocketry entryCost = 14400 cost = 400 category = Propulsion subcategory = 0 title = My Test Empty Cheap Tank manufacturer = Rockomax Conglomerate description = Test part, to test cost calculation in TweakScale

attachRules = 1,1,1,1,0

mass = 1 dragModelType = default maximum_drag = 0.2 minimum_drag = 0.3 angularDrag = 2 crashTolerance = 6 breakingForce = 200 breakingTorque = 200 maxTemp = 2900 MODULE { name = TweakScale defaultScale = 2.5 type = stack }

RESOURCE { name = LiquidFuel amount = 0 maxAmount = 1000 }

}

If the cost is set to 1000, everything works fine in the VAB : it will cost 1000 empty, and 1800 once full. The bug only appears when the wetcost is more than twice the drycost.

Biotronic commented 10 years ago

Have you tested this part without TweakScale installed? Its behavior will be exactly as you describe in the 'actually' section. This has nothing to do with TweakScale.

The reason for this seems to be that the 'cost' field actually assumes the tanks are full. If you look at other fuel tank .cfgs in the game, their cost field will always include the cost of resources (though admittedly those tanks are always full).

So, your tank above costs 400 when full. This would leave the empty cost at -400. KSP clamps this to 0, so when you add fuel back, it costs 800.

abienvenu commented 10 years ago

Yes, for Squad, the 'cost' is the price of full tanks, even if the part.cfg is configured to be empty (amount=0). But as of v1.37, for TweakScale, when amount=0, the 'cost' is the price of empty tanks.

To investigate, I made four different parts, costing 400 or 1000, and configured with amount 0 or 1000.

Without TweakScale :

With TweakScale 1.37 :

So without tweakscale, I can have an empty tank with a drycost of 200 (cost = 1000 / amount = 0). With tweakscale 1.37, I cannot have any tank with a drycost that is lower than the cost of its contents, unless the tank is full by default.

This is an issue for the excellent OKS/MKS mod, where storage tanks should be empty by default. These tanks should have low cost, and can carry costly resources.

Biotronic commented 10 years ago

Great Scott, you're right! The problem is that Scale.cs line 256 uses amount, but should use maxAmount, like Squad does. I'll have to replicate their bug (of course). Already fixed on my machine, and I will make a new release within a few minutes.