Internal Mechanics of TP

I know what TP stands for, and (in a basic sense) what it's used for. But TP has a HUGE amount going on under the hood that isn't really explained anywhere except (I presume) in the code itself.

I need a little help figuring out how exactly this stat works and the types of calculations it's best suited to handle.

What's its base? What stats manipulate it? How does the automatic re-charge work?

With other stats, I set them, see what numbers they return as I run weapon/skill tests, and adjust as needed.....but with TP, I feel like RPG maker has a specific design its asserting, and it's a design I fundamentally do not understand.
Its max value is 100. It doesn't increase with level, TPRG(correct name?) works just like the other regeneration parameters, and everything else is really up to you. To turn off the on-battle random charge and change the thing more granularly you're gonna need a plugin. Out of the box there isn't much too it.
@Weremole that answer is incomplete, you've missed several important points about TP

@ExquisiteCorpse
to add to the answer above, the missing points are:

1) TP is charged by damage, which means that it goes up if the actor is damaged by an enemy skill - consider it something similiar to "adrenaline" in this point.
2) you have to choices of TP mechanics in default, and they are determined by the trait "preserve TP".
If an actor has that trait, the TP at starting any battle will be the TP from the end of the last battle (plus any changes done outside battle which can be done by event code)
If an actor is missing that trait, TP will be randomly set at each battlestart.

There is an additional parameter that manipulates how much TP is gained by damage
To add the answer above, here is the default formula of the TP when taking a damage
Code:
50 * damage_rate * TCR

Damage rate is the rate on how much you get the damage based on the battler max HP. i.e, if your HP is 100 and you get the damage by 60, then the damage rate is 0.6.

TCR is TP Charge Rate, by default it's 1.0, means nothing is changed. If you set the TCR from the traits, it will affect the TP gain.
The precise formulas for charging TP you can see in the code for the Game_Battler object (which you will find in the rpg_objects.js file).

The formula for gaining TP by damage is as you can see:
Code:
Game_Battler.prototype.chargeTpByDamage = function(damageRate) {
    var value = Math.floor(50 * damageRate * this.tcr);
    this.gainSilentTp(value);
};
TCR obviously referring to the TP Charge Rate trait/property of the battler/actor in question. As for what the damageRate argument represents, it's actual a number equal to the damage being taken by the actor divided by their Max HP. You can see it where the function gets called (the only place it gets called to my knowledge):
Code:
Game_Battler.prototype.onDamage = function(value) {
    this.removeStatesByDamage();
    this.chargeTpByDamage(value / this.mhp);
};

EDIT: Ninja'd by TheoAllen.

In that case, here's the formula for assigning the TP at the start of battle (used if Preserve TP isn't set):
Code:
Game_Battler.prototype.initTp = function() {
    this.setTp(Math.randomInt(25));
};
The randomInt() function is actually not a built-in Javascript function, but is instead defined in the rpg_core.js file.
Code:
Math.randomInt = function(max) {
    return Math.floor(max * Math.random());
};
For those unfamiliar with how the built-in Math.random() works, it returns a number between 0 and 1, including 0 but NOT including 1.

That means an actor/battler cannot, in fact, ever actually start with 25 TP. The maximum they will ever start with is 24.
@Weremole that answer is incomplete, you've missed several important points about TP

@ExquisiteCorpse
to add to the answer above, the missing points are:

1) TP is charged by damage, which means that it goes up if the actor is damaged by an enemy skill - consider it something similiar to "adrenaline" in this point.
2) you have to choices of TP mechanics in default, and they are determined by the trait "preserve TP".
If an actor has that trait, the TP at starting any battle will be the TP from the end of the last battle (plus any changes done outside battle which can be done by event code)
If an actor is missing that trait, TP will be randomly set at each battlestart.

There is an additional parameter that manipulates how much TP is gained by damage

Thanks!
Wow.....it looks like some coder brought a bong into the office one week, made a thing and stuck it in the build. By the time people understood what happened, it was too late, and they said "Let's just make Hoshi's thing optional and ship it."

It would probably take me less time to learn enough Java to display a variable as a depleting bar than to figure out how to manipulate TP in a predictable/manageable fashion =P

Thanks for the help, everyone! What a crazy corner of the system.

Original thread: https://forums.rpgmakerweb.com/threads/internal-mechanics-of-tp.107651/