Merge pull request #835 from DanielNoord/tillnextachiev

Some optimizations in Left till next achievement calculations
This commit is contained in:
Daniël van Noord
2021-05-30 10:57:32 +02:00
committed by GitHub
4 changed files with 19 additions and 7 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -26,9 +26,7 @@ export default function AllAmountTillNextAchievement(forceRecalc) {
result[i] = { result[i] = {
AmountNeeded: tillNext, AmountNeeded: tillNext,
TotalNeeded: Game.Objects[i].amount + tillNext, TotalNeeded: Game.Objects[i].amount + tillNext,
price: Game.Objects[i].getSumPrice( price: Game.Objects[i].getSumPrice(tillNext),
Game.Objects[i].amount + tillNext - Game.Objects[i].amount,
),
}; };
} }
}); });

View File

@@ -3,10 +3,24 @@ import { SimAchievementsOwned } from '../../Sim/VariablesAndData';
export default function IndividualAmountTillNextAchievement(building) { export default function IndividualAmountTillNextAchievement(building) {
const AchievementsAtStart = Game.AchievementsOwned; const AchievementsAtStart = Game.AchievementsOwned;
for (let index = 0; index < 101; index++) { let index = 100;
let lastIndexWithChange = 100;
while (index > -1) {
BuyBuildingsBonusIncome(building, index); BuyBuildingsBonusIncome(building, index);
if (SimAchievementsOwned > AchievementsAtStart) { if (SimAchievementsOwned > AchievementsAtStart) {
return index; lastIndexWithChange = index;
index -= 10;
} else if (index === 100) {
return 101;
} else {
index += 1;
while (index <= lastIndexWithChange) {
BuyBuildingsBonusIncome(building, index);
if (SimAchievementsOwned > AchievementsAtStart) {
return index;
}
index += 1;
}
} }
} }
return 101; return 101;