[SDK] How to make building effects multiplicative?

sleepground123

Chieftain
Joined
Nov 28, 2020
Messages
46
In Civ4, multipliers are additive unless a change in DLL is made. For example, cities with both Library and University will get 150%(100% + 25% + 25%) the base amount of science, not 156.25%(100% * 125% * 125%). Which part of the code do I have to change?
 
I think, in CvCity:: processBuilding, the line with the changeCommerceRateModifier call needs to be changed. The modifier gets stored as an integer. Getting the rounding right could be tricky. Normally, Civ 4 rounds integer divisions toward zero. That would mean, however, that adding an Academy before a Library and University results in a different modifier (+133%) than adding the Academy last (+134%) because the rounding errors depend on the order in which the buildings are processed. When a building is removed (negative iChange parameter), one would then have to round up. But if the buildings aren't removed in the same order as they were added, the modifier won't necessarily end up at 0 when all buildings are gone. Well, apart from the WorldBuilder, buildings only get removed by random events.
 
I calculated the modifiers with many different values, and found out that the variation of total modifiers is at most 1%. It is a very small difference and could be ignored.
 
Top Bottom