Internals - pruby/xppylons GitHub Wiki
Internals
Area of effect
The area a pylon affects is proportional to its height. The radius is proportional to the square root of height, scaled so a maximum-size tower has our set maximum radius.
Drain strength, share of energy
The amount of drain from a tower at a point is 0 outside its radius of effect, and (distance / radius) * pylons.pylonDepletion at any point within it. Drains are combined at a point to get the total drain:
- 1st tower strength is 0.2. 0.2 * 1.0 = 0.2. 1.0 - 0.2 leaves 0.8
- 2nd tower strength is 0.3. 0.3 * 0.8 = 0.24. 0.8 - 0.24 leaves 0.56
- 3rd tower strength is 0.1. 0.1 * 0.56 = 0.056. 0.56 - 0.056 leaves 0.504
We then work out how much energy was taken:
- 1.0 - 0.504 = 0.496
The 2nd tower's share of the draw would be:
- 0.3 / (0.2 + 0.3 + 0.1) = 0.5
We multiply that by the total energy taken to get 0.248, reduced from the 0.3 it would get normally.
Energy Field
The energy field is composed of two combined simplex noise generators. We have a base level and a maximum. The medium-distance noise source produces noise from 0 to half (maximum - 1). The long-distance noise source produces numbers from 0 to 2. We multiply those together at a point and add 1 to get the field strength, for a total output of 1 to maximum, with long and shorter range peaks and troughs. Our average should be halfway between 1 and the maximum.
All XP gains are multiplied by the field strength at the sample point.
Calculating exp rate
To calculate exp rate, we pick random points in our area of effect. We choose a random (uniform) distance to the radius, and a random angle. We work out the point associated with that, and work out our share of the energy at that point as above. Multiply our share by the field strength and a scale value, and add to the xp rate.
Our number of samples is proportional to height. If we set samples per level to 2 (the default), then a 20 tall tower will sample and add up 40 points to get its exp rate. Increasing samples makes the end total vary less over time.
The exp rate is recalculated every 10 minutes by default, or when a pylon is activated or deactivated with an overlapping influence. The regular recalculation is likely to be moved in to a separate thread, but is not yet. The same exp rate is used for that period to add exp every 30 seconds by default. This creates the appearance of continuous collection without calculating the rate every time.