Job bonus shown for leader is incorrect

Issue #70 resolved
Boris Zbarsky created an issue

In the village pane, for a rank 7 leader (so with a job bonus of x5.7) I see something like this:

:3 Cassie Berry, 43 years old, Engineer (rank 7)
Scholar +2.14% [master (100%)]

whereas for a non-leader master I see:

:3 Micha Tails, 31 years old, Scientist
Scholar +0.38% [master (100%)]

(this is with augmentations, obviously). The display for the non-leader looks correct-ish; it's actually +37.5%, but it's getting rounded (and forgetting to multiply by 100, if it's going to show a % sign). But the display for the leader is wrong, because the way the leader bonus is applied for calculating production is by first adding the skill bonus to 1 and the multiplying the result by the leader bonus. In my case that's 1.375 * 5.7 = 7.8 or so. So I would expect to see +6.8% displayed, not +2.14%.

The 2.14 is coming from just multiplying 0.375 by 5.7 on this line in village.js:

bonus = bonus > 0 && kitten.isLeader ? this.game.village.getLeaderBonus(kitten.rank) * bonus : bonus;

Instead that should be doing:

bonus = bonus > 0 && kitten.isLeader ? this.game.village.getLeaderBonus(kitten.rank) * (bonus+1) - 1 : bonus;

Comments (5)

  1. freeroot

    As you can see line 283 of village.js, the leader bonus is apply directly from the basic augmentation's bonus without the +1 before.

    diff *= this.getLeaderBonus(kitten.rank);
    

    Tell me if you don't agree.

  2. Boris Zbarsky reporter

    Right, but if you look at what diff is at that point it looks like, we have:

    var mod = this.game.villageTab.getValueModifierPerSkill(kitten.skills[kitten.job] || 0);
    

    So mod is the modifier from the kitten's skill level. Then:

    var diff = job.modifiers[jobResMod] + job.modifiers[jobResMod] * ((mod-1) * productionRatio);
    

    where job.modifiers[jobResMod] is the base kitten production for that job and resource. Then that diff value is multipled by the leader bonus. So rewriting slightly:

    var diff = job.modifiers[jobResMod] * (1 + (mod-1)*productionRatio);
    

    and then this whole thing gets multiplied by the leader bonus, as you say. Agreed so far?

    What is this display trying to show? It's trying to show the percentage boost over not having the skill or leader bonus. That means that computing it means doing this calculation (to get a fraction boost, which will later be converted to a percentage):

    finalValue/baseValue - 1
    

    In our case the baseValue is job.modifiers[jobResMod] and as you point out diff is directly multiplied by the leader bonus, so we have:

    leaderBonus * (1 + (mod-1) * productionRatio) - 1
    

    In the computation cited in the issue, (mod - 1)* productionRatio == bonus, hence the formula I gave.

    Here's a simple numerical example. Say job.modifiers[jobResMod] is 1, to make the calculation simple. Say (mod-1)*productionRatio == 0.10` and the leader bonus is 2. In the calculation on line 283 and slightly preceding, we would have:

    var diff = 1 + 1*0.1;
    diff *= 2;
    

    so diff ends up 2.2. That means the total bonus from skills and leader is 120%. But the bonus display calculation is currently doing, for the leader case:

    var bonus = 0.10;
    bonus = bonus * 2;
    

    and hence producing 0.2 which gets shown as a 20% bonus.

    Am I missing something in the calculations above?

  3. freeroot

    Ok, I have not seen that the LeaderBonus were computing including the job.modifier bonus AND the job.modifier itself. I have made some calculations to convince me.

    You right, I change the display.

    Example :

    job.modifiers[jobResMod] = 0.05 (scholar)

    mod = 1.75 (master)

    productionRatio = 0.5

    leaderBonus = 5.7

    var diff = job.modifiers[jobResMod] + job.modifiers[jobResMod] * ((mod-1) * productionRatio);
    
    => var diff = 0.05 + 0.05 * ((1.75-1) * 1
    
    => var diff = 0.06875
    
    So diff  / job.modifiers[jobResMod] = 0.06875 / 0.05 = 1.375
    

    So the difference between job.modifiers[jobResMod] and diff is +37.5%.

    diff *= this.getLeaderBonus(kitten.rank);
    
    => diff = 0.06875 * 5.7
    
    => diff = 0.391875
    
    So diff  / job.modifiers[jobResMod] = 0.391875 / 0.05 = 7,8375
    

    So the difference between job.modifiers[jobResMod] and diff is +683.75%.

    ps: the placement of the point in those percentages have been already corrected in a commit.

  4. Log in to comment