Based on Ctrl-F in the source code, for all the aliases of "set overflow research" evaluated at 0, it seems there is indeed exactly one place and one time your overflow is zeroed - when your research occurs at start of turn.
Now, the issue to understanding these mechanics (well, one of the myriad issues) is that there are two distinct things that might casually be termed "overflow". In order to explain the process, I will use some new, unbound terminology.
Could you explain it in simple terms ? :/ Or with an example.
Sure. I made a mistake in interpreting earlier. I can't explain it with an example, though, as I don't understand how examples explain things.
So, I was really surprised to find that teams don't have their own overflow. Apparently if you're playing a team game, you should have the first player to go on your team nurture all the overflow, to get any tech you're researching together as soon as possible. Meanwhile the rest of ya should bulb science.
First I'll give the situation for a non-team game. Then if I have time I guess I can diagram the whole thing.
Terminology:
Multiplier: Hopefully obvious
Modifier: An expression of a percentage which adds up with other modifiers with which it is grouped, which expresses an amount increased to a base quantity as a fraction of that quantity. The modifiers you see in the game are grouped by default to wherever the game entity that houses the modifier lives - to a city or your empire.
So they're added within a group, and multiplied group-by-group.
There's a lot of malicious rounding that goes on in the research functions. Even though the game claims to track hundredths of a beaker, those get rounded off at almost every step. Still, all the units are nominatively hundredths of a beaker, so we'll pretend.
Every player has their own tech tree. A certain number describes your relationship to each tech on the tree - how much science you've put into that tech. I will call this "Accumulated beakers". You also have your own measure of overflow accumulated. This is a number that belongs to you, the player, and has
no relationship to a tech.
The sum of these two numbers is your ResearchProgress. It is a quantity of (hundredths of) beakers.
Any time something gives you science, it ends up going through the "SetResearchProgressTimes100" method. But it does that first by going through this statement:
Code:
SetResearchProgressTimes100(eIndex, (GetResearchProgressTimes100(eIndex) + iChange), ePlayer);
This statement is what gets called when the function to increment or accumulate to your research is called. It invokes functions for the team research, which does not have overflow. It invokes the set function on the amount "This team's ResearchProgress + the amount you're adding".
To be sure this is the whole picture, I would have to know the context of -every single- call to this function, and whether any math takes place on the numbers put into it. The logic of handling research should exist in one and only one place, but in fact it does not - some of it exists in doResearch(), which is exactly why the glitch exists. I'll get to that.
The function SetResearchProgressTimes100() sets your team's accumulation of beakers for the current tech, and calculates the cost of that tech, which is the raw cost multiplied by two things, each of which is a sum of modifiers. The first factor is Civs who know the tech , and the Scholars in Residence resolution. The second factor is the city count penalty. Based on the XML files in Assets, up to 30% of the cost of a tech is discounted, as a proportion of the number of met civs with the tech out of all living major civs. 30% doesn't sound right, but it is calculated as a proportion. And 20% of the cost is discounted with Scholar's in Residence (which actually means it increases the rate of acquiring the tech by 25%, on its own). Let's suppose the actual discount from met civs is 1% and the Scholars resolution is passed.
So that is applied as 79% (=100 +(-20) +(-1)) multiplied to the cost of the tech. Then that modified cost gets modified by the City count rule, +5% cost for each city. If you have 4 cities that's 115% multiplier. If these were both active that's 90.85% of the base cost.
This is the adjusted cost, BaseCost * (100 + ScholarsResolutionModifier + Technological Diffusion Modifier)% * ExtraCostFromCitiesMultiplier = actual Cost
At the very moment your research is adjusted with new beakers, this actual cost - which you can see is based on the rules and is kept absolutely up to date based on any changes - is subtracted from your ResearchProgress, to obtain what we will call "Overshot Beakers". That formula again is, for the current tech:
(Team Accumulated beakers) - (base tech cost * (100 + ScholarsResolutionModifier + Technological Diffusion Modifier)% * ExtraCostFromCitiesMultiplier)
where accumulated beakers is previously accumulated beakers + the change amount, so, substituting from the ChangeResearchProgress() call, is actually
(Previously accumulated beakers + change amount) - (base tech cost * (100 + ScholarsResolutionModifier + Technological Diffusion Modifier)% * ExtraCostFromCitiesMultiplier)
The preceding formula is your "Overshot beakers", and it is your Overshot beakers to which the cap is applied. This is not your overflow; this is the measure of surpassing the current tech. When your overshot beakers are 0 or more, it means you completed the tech. And notice, since the above equation does not involve your overflow, it means your overflow does not get you science.
Before we go further, let's call your privately owned overflow quantity your "Excess beaker stockpile". If you get a tech, then your Overshot beakers are added to your Excess beaker stockpile. Actually in a team game, the player responsible for overshooting the tech gets the excess beakers.
The last part of this mystery is the doResearch function, which as I said is the only place your overflow gets zeroed. I already quoted that function.
The bulb call, which I looked up, is straightforward. It calls the previous function on the change amount equal to the bulb quantity.
I will have to come in and give a complete rundown of the process in a separate,
yet other, post.
I know why the exploit exists. I also know it's still there in a certain form - it's just harder to control the numbers to use, like flying a nanomachine through a cheerio.
edit: with an original NES controller.