[BNW] [C++] Specialist Food Consumption issue

ThanOscar

Chieftain
Joined
Feb 13, 2019
Messages
41
I am replacing the halfspecialistfood boolean (Why is it a boolean?!??!?!) with a modifier, but it doesn't apply properly, if i set the modifier to 25, and put a citizen in a university nothing happens, if i set two or more each citizen gives 1 back think its because it goes in decimal numbers and its an integer. Here's the code:

Code:
int CvCity::foodConsumption(bool /*bNoAngry*/, int iExtra) const
{
    VALIDATE_OBJECT
    int iPopulation = getPopulation() + iExtra;

    int iFoodPerPop = /*2*/ GC.getFOOD_CONSUMPTION_PER_POPULATION();

    int iNum = iPopulation * iFoodPerPop;

    // Specialists eat less food? (Policies, etc.)
    if(GET_PLAYER(getOwner()).getSpecialistFoodModifier() != 0) //OR MORE?
    {
        int iFoodSpecialists = GetCityCitizens()->GetTotalSpecialistCount() * iFoodPerPop;
        int iFoodModifier = GET_PLAYER(getOwner()).getSpecialistFoodModifier();
        iFoodSpecialists = iFoodSpecialists * iFoodModifier / 100;
        iNum -= iFoodSpecialists;
    }

    return iNum;
}

do i have to make this function return a float? It seems messy
 
iFoodSpecialists = iFoodSpecialists * iFoodModifier / 100;

is

iFoodSpecialists = iSpecialists * 2 * 25 / 100;

if iSpecialists = 1, this is 1 * 2 * 25 / 100, which is 0
if iSpecialists = 2, this is 2 * 2 * 25 / 100, which is 1
if iSpecialists = 3, this is 3 * 2 * 25 / 100, which is 1
if iSpecialists = 4, this is 4 * 2 * 25 / 100, which is 2

which is how Civ5 behaves, because it uses ints. Even when using decimals, it uses ints, just multiplied by 100.

Floats have issues when being saved, so Civ5 doesn't use them
 
aw, does this mean its much more complicated to give a modifier that doesnt return a round number such as 33% of normal food usage?
 
Just add your modifier in two parts - multiplier and divisor. 33.333333% is then "multiplier = 1, divisor = 3", 25% is "multiplier = 1, divisor = 4" - there are numerous such examples in my modded DLL
 
Like this? If not can you point me to an example? I searched by Divisor to find one

Code:
        iFoodSpecialists *= (100 + iFoodModifier);
        iFoodSpecialists /= 100;
        iNum -= iFoodSpecialists;
 
Well i got it to work (using negative values in the table seems to do the trick, math is not my strong suit definitely) but they are not displayed properly in the city interface, i wanted it to display to the decimal the amount of food saved by a specialist such as 0.6, oh well, at least it works
 
Back
Top Bottom