Skip to content

Commit

Permalink
safer number checks
Browse files Browse the repository at this point in the history
  • Loading branch information
genbtc committed Mar 29, 2018
1 parent 1ffdfe2 commit 75ed86a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion modules/breedtimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function autoBreedTimer() {
var numgens = Math.ceil(Math.log10(targetBreed / timeOK) / Math.log10(1.02));
//debug("2a. Time: " + getBreedTime(true) + " / " + getBreedTime(),"breed");
//debug("2b. " + numgens + " Genes.. / " + game.jobs.Geneticist.owned + " -> " + (game.jobs.Geneticist.owned+numgens),"breed");
if (isNaN(numgens)) numgens = 0;
if (Number.isNaN(numgens)) numgens = 0;
safeBuyJob('Geneticist', numgens);
//debug("This many Geneticists were FIRED: " + numgens + ". Jobs Now: " + game.jobs.Geneticist.owned, "breed");
//debug("2c. Time: " + getBreedTime(true) + " / " + getBreedTime(),"breed" );
Expand Down
13 changes: 7 additions & 6 deletions modules/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ MODULES["jobs"].autoRatio1 = [1,1,1];
MODULES["jobs"].customRatio; //set this like above and it will Auto use it.

function safeBuyJob(jobTitle, amount) {
if (!Number.isFinite(amount) || amount === 0 || typeof amount === 'undefined') {
//debug("Exiting out of buyjob early " + jobTitle + " " + amount);
if (!Number.isFinite(amount) || amount === 0 || typeof amount === 'undefined' || Number.isNaN(amount)) {
//debug("Exiting out of buyjob early " + jobTitle + " " + amount,"jobs");
return false;
}
var old = preBuy2();
Expand Down Expand Up @@ -54,7 +54,7 @@ function safeFireJob(job,amount) {
var x = 1;
if (amount != null)
x = amount;
if (!Number.isSafeInteger(oldjob)){
if (!Number.isFinite(oldjob)){
while (oldjob == test) {
test-=x;
x*=2;
Expand Down Expand Up @@ -205,9 +205,10 @@ function buyJobs() {
var toBuy = Math.floor((jobratio / totalRatio) * totalDistributableWorkers) - game.jobs[job].owned - subtract;
var canBuy = Math.floor(game.resources.trimps.owned - game.resources.trimps.employed);
var amount = toBuy <= canBuy ? toBuy : canBuy;
safeBuyJob(job, amount);
/* if (amount > 0)
debug("Jobbing: " + job + " " + amount); */
if (amount != 0) {
safeBuyJob(job, amount);
//debug("Ratio Buying Job: " + job + " " + amount + " " + jobratio, "jobs");
}
return true;
}
else
Expand Down

0 comments on commit 75ed86a

Please sign in to comment.