Version 1.11.1 1.11.1
[AntennaRange.git] / README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# AntennaRange
A KSP mod that enforces and encourages the use of the bigger antennas.

# For Part Developers
## The Fields
AntennaRange extends and augments the functionality of the stock ModuleDataTransmitter through the new `ModuleLimitedDataTransmitter` class. This class uses four additional configurable fields to define the part's behavior.

`nominalRange` is the range, in meters, at which the part should function identically to the stock module, i.e. without any modification to the power cost or packet size. This is used along with maxPowerFactor to calculate the maximum range of the part.  
`simpleRange` is the same as nominalRange, but is used when the mod is in "simple" mode. In general it will probably need to be a much larger number than nominalRange.  
`maxPowerFactor` effectively sets the maximum range of the antenna by essentially capping how much the power may be "turned up" to get better range. I originally used 8 for this number, because it felt right. I've since used 4 (for my DTS) and 16 (for my Comm. 88-88). You don't want this number to be too high, or small probes will go uncontrollable a lot when transmitting.  
`maxDataFactor` defines the maximum "speed up" bonus that comes from using antennas at less their nominal range. I originally used 4 for this number for all parts; the DTS has a higher bonus now.

Note that all of the fields needed for Squad's `ModuleDataTransmitter` still need to be filled out. Depending on how you're defining your parts, they might need to go in your AntennaRange patch, or they might already be defined on the base part.

## The Mechanic
In general, the scaling functions assume the relation `D² α P/R,` where D is the total transmission distance, P is the transmission power, and R is the data rate.  Data rate increases as range decreases below nominalRange: `R α nominalRange² / D²`.  By default, power use increases as range increases above `nominalRange`: `P α D² / nominalRange²`.  Optionally, power use may remain fixed, and data rate instead decreases as range increases above `nominalRange`: `R α nominalRange² / D²`.

## Patch Conventions
To maximize cross-compatibility, please consider the following conventions for ModuleManager patches regarding AntennaRange:

When providing new definitions for your own parts, always specify a `:FOR[YourModHere]` pass name.
Whenever changing default AntennaRange definitions (e.g. if you were going to rebalance my antennas to suit your mod), please do so in the `:AFTER[AntennaRange]` pass.
I recommend providing all optional functionality (e.g. enabling RemoteTech vs. AntennaRange modules) in separate patches using `:NEEDS[]` blocks.

A sample AntennaRange configuration for an all-new mod part might look like this:
```
@PART[modPartName]:FOR[YourModName]:NEEDS[AntennaRange,!RemoteTech]
{
	MODULE
	{
		// ### Module Definition ###
		name = ModuleLimitedDataTransmitter
		
		// ### Squad Definitions ###
		// Delay between transmission packets, in seconds
		packetInterval = 0.10
		
		// Data capacity of nominal transmission packets, in MiT
		packetSize = 2
		
		// Resource cost of nominal transmission packets, in units
		packetResourceCost = 20.0
		
		// Resource name to be consumed by transmission
		requiredResource = ElectricCharge
		
		// Animation module index, 0-based, of the antenna extend/retract animation
		DeployFxModules = 0
		
		// ### AntennaRange Defintions ###
		// Range, in meters, at which the antenna behaves per the "nominal" characteristics above
		// Used with "additive" ranges.
		nominalRange = 10000000000
		
		// Range, in meters, at which the antenna behaves per the "nominal" characteristics above
		// Used with "simple" ranges.
		simpleRange = 56250000000
		
		// The maxmimum multiplier on packetResourceCost, essentially defining the maximum power output of the
		// transmitter.  Maximum range is defined as: maxTransmitDistance = nominalRange * sqrt(maxPowerFactor)
		maxPowerFactor = 16
		
		// The maximum multiplier on packetSize, essentially defining the maximum data throughput of the
		// transmitter.
		maxDataFactor = 2
	}
	
	// We add this ModuleScienceContainer so that when transmission fails the antennas can try to stash the data instead of dumping it to the void.
	MODULE
	{
		name = ModuleScienceContainer

		dataIsCollectable = true
		dataIsStorable = false

		storageRange = 2
	}
}
```

This example assumes that the base part definition does not include a `ModuleDataTransmitter` module, or any RT modules. If the base part definition includes a `ModuleDataTransmitter` module, a sample AntennaRange patch could look like this:
```
@PART[modPartName]:FOR[YourModName]:NEEDS[AntennaRange,!RemoteTech]
{
	@MODULE[ModuleDataTransmitter]
	{
		@name = ModuleLimitedDataTransmitter
		nominalRange = 10000000000
		simpleRange = 56250000000
		maxPowerFactor = 16
		maxDataFactor = 2
	}
	
	// We add this ModuleScienceContainer so that when transmission fails the antennas can try to stash the data instead of dumping it to the void.
	MODULE
	{
		name = ModuleScienceContainer

		dataIsCollectable = true
		dataIsStorable = false

		storageRange = 2
	}
}
```

IIRC, RemoteTech parts should not have `ModuleDataTransmitter` definitions. In that case, to facilitate RT, AR, and Stock compatibility, a suite of patches like this might be appropriate:

```
// If we don't have RemoteTech, add a stock ModuleDataTransmitter first.
@PART[modPartName]:NEEDS[!RemoteTech]:BEFORE[YourModName]
{
	MODULE
	{
		// ### Module Definition ###
		name = ModuleDataTransmitter
		
		// ### Squad Definitions ###
		// Delay between transmission packets, in seconds
		packetInterval = 0.10
		
		// Data capacity of nominal transmission packets, in MiT
		packetSize = 2
		
		// Resource cost of nominal transmission packets, in units
		packetResourceCost = 20.0
		
		// Resource name to be consumed by transmission
		requiredResource = ElectricCharge
		
		// Animation module index, 0-based, of the antenna extend/retract animation
		DeployFxModules = 0
	}
}

// If AntennaRange is installed, convert that to a ModuleLimitedDataTransmitter
@PART[modPartName]:NEEDS[AntennaRange,!RemoteTech]:FOR[YourModName]
{
	@MODULE[ModuleDataTransmitter]
	{
		// ### Module Redefinition ###
		@name = ModuleLimitedDataTransmitter
		
		// ### AntennaRange Defintions ###
		// Range, in meters, at which the antenna behaves per the "nominal" characteristics above
		// Used with "additive" ranges.
		nominalRange = 10000000000
		
		// Range, in meters, at which the antenna behaves per the "nominal" characteristics above
		// Used with "simple" ranges.
		simpleRange = 56250000000
		
		// The maxmimum multiplier on packetResourceCost, essentially defining the maximum power output of the
		// transmitter.  Maximum range is defined as: maxTransmitDistance = nominalRange * sqrt(maxPowerFactor)
		maxPowerFactor = 16
		
		// The maximum multiplier on packetSize, essentially defining the maximum data throughput of the
		// transmitter.
		maxDataFactor = 2
	}

	// We add this ModuleScienceContainer so that when transmission fails the antennas can try to stash the data instead of dumping it to the void.
	MODULE
	{
		name = ModuleScienceContainer

		dataIsCollectable = true
		dataIsStorable = false

		storageRange = 2
	}
}

// If RemoteTech is installed, do their module(s) instead
@PART[modPartName]:NEEDS[RemoteTech]:FOR[YourModName]
{
	// RemoteTech module(s) here
}
```

## Useful Formulas

### Per Antenna
`nominalRange` is a given, and is never calculated
`maxPowerFactor` is a given, and is never calculated
`maxTransmitDistance = nominalRange * sqrt(maxPowerFactor)`

### Per Link
A "link" is any connected pair of antennas.  
`NominalLinkDistance = sqrt(nominalRange1 * nominalRange2)`  
`MaxLinkDistance = sqrt(maxTransmitDistance1 * maxTransmitDistance2)`

Therefore, to find the `MaxLinkDistance` from two sets of `nominalRange` and `maxPowerFactor`:  
`MaxLinkDistance = sqrt(nominalRange1 * sqrt(maxPowerFactor1) * nominalRange2 * sqrt(maxPowerFactor2))`

To find a single antenna's `nominalRange` from a desired `maxTransmitDistance` given its `maxPowerFactor`:  
`nominalRange = maxTransmitDistance / sqrt(maxPowerFactor)`

To find a single antenna's desired maximum range given the desired maximum link distance and another set `maxTransmitDistance`:  
`maxTransmitDistance1 = MaxLinkDistance * MaxLinkDistance / maxTransmitDistance2`

Remember that `maxPowerFactor` may differ between antennas (and does, in my lastest configs: longAntenna is 8, mediumDish is 4, commDish is 16).

Currently Kerbin's `maxPowerFactor` is hard-coded as 8.

Feel free to use this spreadsheet for balancing antennas if it's useful to you: https://goo.gl/ChsbfL

## On Balance
In my configs I've balanced the three stock antennas to cover all of the stock solar system. Since you're introducing five more antennas and working with OPM, you will probably want to change the behavior of the stock parts and diversify the range to gradually cover the whole OPM system. Since you have some parts specifically designed for use in planetary subsystems, their balance when transmitting to other parts is probably more important than their balance when transmitting to Kerbin. For longer range parts designed to make the whole interplanetary leap, the inverse is probably true.

Feel free to ask questions! If anything's unclear or you just want to bounce balance ideas off of me, don't be shy. I'm always happy to help.